定義和用法
這個mysqli_info()函數返回有關最近 MySQLi 函數調用執行的查詢的信息。此函數僅支持以下格式的查詢:
插入...選擇....
插入...值 (...),(...),(...)。
加載數據文件....
更改表....
更新 ....
用法
mysqli_info($con)
參數
Sr.No | 參數及說明 |
---|---|
1 |
con(Mandatory) 這是一個表示與 MySQL 服務器的連接的對象。 |
返回值
PHP mysqli_info() 函數返回一個字符串值,表示最近執行的查詢的描述/信息。如果執行的最新查詢不是受支持的查詢之一,則此函數返回一個空字符串。
PHP版本
這個函數最初是在 PHP 版本 5 中引入的,適用於所有後續版本。
示例
以下示例演示了 mysqli_info() 函數的用法(程序風格) -
<?php
//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//Query to insert a record into the employee table
mysqli_query($con, "INSERT INTO employee VALUES ('Sarmista', 'Sharma', 28, 'F', 15000, 101), ('Sheldon', 'Cooper', 25, 'M', 2256, 102)");
//Query Info
$error = mysqli_info($con);
print("Query Info:".$error);
//Closing the connection
mysqli_close($con);
?>
這將產生以下結果 -
Query Info:Records:2 Duplicates:0 Warnings:0
示例
在麵向對象的風格中,這個函數的語法是 $con ->info。以下是麵向對象風格的此函數的示例 -
<?php
//Creating a connection
$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)");
//Query Info
$info = $con ->info;
print("Query Info:".$info);
//Closing the connection
$con -> close();
?>
這將產生以下結果 -
Query Info:Records:2 Duplicates:0 Warnings:0
示例
以下是 mysqli_info() 函數的另一個示例 -
<?php
//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//ALTER TABLE Query
mysqli_query($con, "ALTER TABLE table_name DROP COLUMN CONTACT");
print("Info:".mysqli_info($con)."\n");
//UPDATE Query
mysqli_query($con, "UPDATE employee set INCOME=INCOME+5000");
print("Info:".mysqli_info($con)."\n");
//INSERT Query
mysqli_query($con, "INSERT INTO employee (FIRST_NAME, AGE) VALUES (Archana, 25), (Bhuvan, 29)");
print("Info:".mysqli_info($con)."\n");
//INSERT Query using SELECT
mysqli_query($con, "INSERT into employee(FIRST_NAME, LAST_NAME, AGE) select 'Manoj', 'Tiwari', 45");
print("Info:".mysqli_info($con)."\n");
//Closing the connection
mysqli_close($con);
?>
這將產生以下結果 -
Info: Info:Rows matched:3 Changed:3 Warnings:0 Info:Rows matched:3 Changed:3 Warnings:0 Info:Records:1 Duplicates:0 Warnings:0
示例
<?php
$connection_mysql = mysqli_connect("localhost","root","password","mydb");
if (mysqli_connect_errno($connection_mysql)){
echo "Failed to connect to 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);
?>
這將產生以下結果 -
Records:7 Duplicates:0 Warnings:0
相關用法
- PHP mysqli_insert_id()用法及代碼示例
- PHP mysqli_init()用法及代碼示例
- PHP mysqli_get_server_info()用法及代碼示例
- PHP mysqli_data_seek()用法及代碼示例
- PHP mysqli_fetch_assoc()用法及代碼示例
- PHP mysqli_connect_error()用法及代碼示例
- PHP mysqli_fetch_all()用法及代碼示例
- PHP mysqli_next_result()用法及代碼示例
- PHP mysqli_stmt_affected_rows()用法及代碼示例
- PHP mysqli_begin_transaction()用法及代碼示例
- PHP mysqli_real_escape_string()用法及代碼示例
- PHP mysqli_fetch_lengths()用法及代碼示例
- PHP mysqli_character_set_name()用法及代碼示例
- PHP mysqli_free_result()用法及代碼示例
- PHP mysqli_fetch_row()用法及代碼示例
- PHP mysqli_debug()用法及代碼示例
- PHP mysqli_commit()用法及代碼示例
- PHP mysqli_fetch_field()用法及代碼示例
- PHP mysqli_kill()用法及代碼示例
- PHP mysqli_thread_safe()用法及代碼示例
注:本文由純淨天空篩選整理自 PHP mysqli_info() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。