PHP mysqli_info() 函数



定义和用法

mysqli_info() 函数返回最近一次 MySQLi 函数调用执行的查询的信息。此函数仅支持以下格式的查询

  • INSERT INTO...SELECT....

  • INSERT INTO...VALUES (...),(...),(...).

  • LOAD DATA INFILE ....

  • ALTER TABLE ....

  • UPDATE ....

语法

mysqli_info($con)

参数

序号 参数及说明
1

con(必填)

此对象表示与 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_function_reference.htm
广告