mysqli_info()函數(shù)返回最近執(zhí)行的 SQL 語句的信息
mysqli_info()函數(shù)返回有關(guān)最近MySQLi函數(shù)調(diào)用執(zhí)行的查詢的信息。此函數(shù)支持僅以下格式的查詢:
INSERT INTO...SELECT....
INSERT INTO...VALUES (...),(...),(...).
LOAD DATA INFILE ....
ALTER TABLE ....
UPDATE ....
mysqli_info($con)
序號 | 參數(shù)及說明 |
---|---|
1 | con(必需) 這是一個表示與MySQL Server的連接的對象。 |
PHP mysqli_info()函數(shù)返回一個字符串值,該字符串值表示最近執(zhí)行的查詢的描述/信息。如果執(zhí)行的最新查詢不是受支持的查詢,則此函數(shù)返回一個空字符串。
此函數(shù)最初是在PHP版本5中引入的,并且可以在所有更高版本中使用。
以下示例演示了mysqli_info()函數(shù)的用法(面向過程風(fēng)格)-
<?php //建立連接 $con = mysqli_connect("localhost", "root", "password", "mydb"); //查詢并將記錄插入到employee表中 mysqli_query($con, "INSERT INTO employee VALUES ('Sarmista', 'Sharma', 28, 'F', 15000, 101), ('Sheldon', 'Cooper', 25, 'M', 2256, 102)"); //查詢信息 $error = mysqli_info($con); print("查詢信息: ".$error); //關(guān)閉連接 mysqli_close($con); ?>
輸出結(jié)果
查詢信息: Records: 2 Duplicates: 0 Warnings: 0
在面向?qū)ο蟮臉邮街?,此函?shù)的語法為$ con-> info。以下是面向?qū)ο髽邮降拇撕瘮?shù)的示例-
<?php //建立連接 $con = new mysqli("localhost", "root", "password", "mydb"); //Query to retrieve all the rows of employee table $con -> query("INSERT INTO employee VALUES ('Sarmista', 'Sharma', 28, 'F', 15000, 101), ('Sheldon', 'Cooper', 25, 'M', 2256, 102)"); //查詢信息 $info = $con ->info; print("查詢信息: ".$info); //關(guān)閉連接 $con -> close(); ?>
輸出結(jié)果
查詢信息: Records: 2 Duplicates: 0 Warnings: 0
以下是mysqli_info()函數(shù)的另一個示例-
<?php //建立連接 $con = mysqli_connect("localhost", "root", "password", "mydb"); //ALTER TABLE 查詢 mysqli_query($con, "ALTER TABLE table_name DROP COLUMN CONTACT"); print("Info: ".mysqli_info($con)."\n"); //UPDATE 查詢 mysqli_query($con, "UPDATE employee set INCOME=INCOME+5000"); print("Info: ".mysqli_info($con)."\n"); //INSERT 查詢 mysqli_query($con, "INSERT INTO employee (FIRST_NAME, AGE) VALUES (Archana, 25), (Bhuvan, 29)"); print("Info: ".mysqli_info($con)."\n"); //INSERT 插入使用 SELECT語句 mysqli_query($con, "INSERT into employee(FIRST_NAME, LAST_NAME, AGE) select 'Manoj', 'Tiwari', 45"); print("Info: ".mysqli_info($con)."\n"); //關(guān)閉連接 mysqli_close($con); ?>
輸出結(jié)果
Info: Info: Rows matched: 3 Changed: 3 Warnings: 0 Info: Rows matched: 3 Changed: 3 Warnings: 0 Info: Records: 1 Duplicates: 0 Warnings: 0
返回最近執(zhí)行查詢的信息:
<?php $connection_mysql = mysqli_connect("localhost","root","password","mydb"); if (mysqli_connect_errno($connection_mysql)){ echo "連接MySql失敗: " . mysqli_connect_error(); } $sql1 = "CREATE TABLE NewTable SELECT * FROM(employee)"; mysqli_query($connection_mysql,$sql1); echo mysqli_info($connection_mysql); mysqli_close($connection_mysql); ?>
輸出結(jié)果
Records: 7 Duplicates: 0 Warnings: 0