<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$city = "Amersfoort";
/* 创建一个准备好的语句 */
$stmt = $mysqli->stmt_init();
$stmt->prepare("SELECT District FROM City WHERE Name=?");
/* 绑定参数以标记 */
$stmt->bind_param("s", $city);
/* 执行查询 */
$stmt->execute();
/* 绑定结果变量 */
$stmt->bind_result($district);
/* 获取值 */
$stmt->fetch();
printf("%s is in district %s\n", $city, $district);
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$city = "Amersfoort";
/* 创建一个准备好的语句 */
$stmt = mysqli_stmt_init($link);
mysqli_stmt_prepare($stmt, "SELECT District FROM City WHERE Name=?");
/* 绑定参数以标记 */
mysqli_stmt_bind_param($stmt, "s", $city);
/* 执行查询 */
mysqli_stmt_execute($stmt);
/* 绑定结果变量 */
mysqli_stmt_bind_result($stmt, $district);
/* 获取值 */
mysqli_stmt_fetch($stmt);
printf("%s is in district %s\n", $city, $district);
Amersfoort is in district Utrecht