PHP mysqli_stmt_init()関数
ステートメントを初期化し、mysqli_stmt_prepare() が使用するオブジェクトを返します:
<?php
// 假定数据库用户名:root,密码:123456,数据库:サンプル
$con=mysqli_connect("localhost","root","123456","サンプル");
if (mysqli_connect_errno($con))
{
echo "连接 MySQL 失败: " . mysqli_connect_error();
}
// 修改数据库连接字符集为 utf8
mysqli_set_charset($con,"utf8");
$country="CN";
// 创建预处理语句
$stmt=mysqli_stmt_init($con);
if (mysqli_stmt_prepare($stmt,"SELECT name FROM websites WHERE country=?"))
{
// 绑定参数
mysqli_stmt_bind_param($stmt,"s",$country);
// 执行查询
mysqli_stmt_execute($stmt);
// 绑定结果变量
mysqli_stmt_bind_result($stmt,$name);
// 获取值
mysqli_stmt_fetch($stmt);
printf("%s 国家的网站为:%s",$country,$name);
// 关闭预处理语句
mysqli_stmt_close($stmt);
}
mysqli_close($con);
?>
定義と使用方法
mysqli_stmt_init() 関数はステートメントを初期化し、mysqli_stmt_prepare() が使用するオブジェクトを返します。
構文
mysqli_stmt_init(connection);
| パラメータ | 説明 |
|---|---|
| connection | 必須。使用する MySQL 接続を指定します。 |
技術詳細
| 戻り値: | オブジェクトを返します。 |
|---|---|
| PHP バージョン: | 5+ |
PHP MySQLi リファレンスマニュアル その他の拡張機能