(PHP 5, PHP 7, PHP 8)
mysqli::$info -- mysqli_info — 返回最近執(zhí)行的 SQL 語(yǔ)句的信息
面向?qū)ο箫L(fēng)格
過(guò)程化風(fēng)格
mysqli_info() 函數(shù)返回一個(gè)包含 最近執(zhí)行的 SQL 語(yǔ)句信息的字符串。 下面有一些參考樣例:
SQL 語(yǔ)句類(lèi)型 | 返回結(jié)果字符串示例 |
---|---|
INSERT INTO...SELECT... | Records: 100 Duplicates: 0 Warnings: 0 |
INSERT INTO...VALUES (...),(...),(...) | Records: 3 Duplicates: 0 Warnings: 0 |
LOAD DATA INFILE ... | Records: 1 Deleted: 0 Skipped: 0 Warnings: 0 |
ALTER TABLE ... | Records: 3 Duplicates: 0 Warnings: 0 |
UPDATE ... | Rows matched: 40 Changed: 40 Warnings: 0 |
注意:
如果所執(zhí)行的 SQL 語(yǔ)句不是上面列出來(lái)的這幾種類(lèi)型的, mysqli_info() 函數(shù)會(huì)返回一個(gè)空字符串。
最近執(zhí)行的 SQL 語(yǔ)句的相關(guān)信息。
示例 #1 $mysqli->info 例程
面向?qū)ο箫L(fēng)格
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* 檢查連接 */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("CREATE TEMPORARY TABLE t1 LIKE City");
/* INSERT INTO .. SELECT */
$mysqli->query("INSERT INTO t1 SELECT * FROM City ORDER BY ID LIMIT 150");
printf("%s\n", $mysqli->info);
/* 關(guān)閉連接 */
$mysqli->close();
?>
過(guò)程化風(fēng)格
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* 檢查連接 */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_query($link, "CREATE TEMPORARY TABLE t1 LIKE City");
/* INSERT INTO .. SELECT */
mysqli_query($link, "INSERT INTO t1 SELECT * FROM City ORDER BY ID LIMIT 150");
printf("%s\n", mysqli_info($link));
/* 關(guān)閉連接 */
mysqli_close($link);
?>
以上例程會(huì)輸出:
Records: 150 Duplicates: 0 Warnings: 0