执行单个 SQL 查询。使用 store_result() 存储结果:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
$mysqli -> real_query("SELECT * FROM Persons");
if ($mysqli -> field_count) {
$result = $mysqli -> store_result();
$row = $result -> fetch_row();
// Free result set
$result -> free_result();
}
$mysqli -> close();
?>
real_query() / mysqli_real_query() 函数执行单个 SQL 查询。可以使用 store_result() 或 use_result() 函数检索或存储结果。
$mysqli -> real_query(
query)
mysqli_real_query(
connection, query)
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
query | Required. The query to be executed |
返回值: | 成功则为真。失败时为 FALSE |
---|---|
PHP 版本: | 5+ |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!