<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* 创建表不返回结果集 */
$mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City");
printf("Table myCity successfully created.\n");
/* 选择查询返回结果集 */
$result = $mysqli->query("SELECT Name FROM City LIMIT 10");
printf("Select returned %d rows.\n", $result->num_rows);
/* 如果我们必须检索大量数据,我们使用 MYSQLI_USE_RESULT */
$result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT);
/* 注意,在所有记录完全检索或结果集关闭之前,我们无法执行任何与服务器交互的函数。
所有调用都将返回“不同步”错误 */
$mysqli->query("SET @a:='this will not work'");
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* 创建表不返回结果集 */
mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City");
printf("Table myCity successfully created.\n");
/* 选择查询返回结果集 */
$result = mysqli_query($link, "SELECT Name FROM City LIMIT 10");
printf("Select returned %d rows.\n", mysqli_num_rows($result));
/* 如果我们需要检索大量数据,我们使用 MYSQLI_USE_RESULT */
$result = mysqli_query($link, "SELECT * FROM City", MYSQLI_USE_RESULT);
/* 注意,在我们检索完所有记录或关闭结果集之前,我们不能执行任何与服务器交互的函数。
所有调用都将返回“不同步”错误 */
mysqli_query($link, "SET @a:='this will not work'");
Table myCity successfully created.
Select returned 10 rows.
Fatal error: Uncaught mysqli_sql_exception: Commands out of sync; you can't run this command now in...