PHP mysqli_stmt_init() 函数
2018-12-08 17:53 更新
PHP mysqli_stmt_init() 函数
实例
初始化声明并返回 mysqli_stmt_prepare() 使用的对象:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$city="Sandnes";
// Create a prepared statement
$stmt=mysqli_stmt_init($con);
if (mysqli_stmt_prepare($stmt,"SELECT District FROM City WHERE Name=?"))
{
// Bind parameters
mysqli_stmt_bind_param($stmt,"s",$city);
// Execute query
mysqli_stmt_execute($stmt);
// Bind result variables
mysqli_stmt_bind_result($stmt,$district);
// Fetch value
mysqli_stmt_fetch($stmt);
printf("%s is in district %s",$city,$district);
// Close statement
mysqli_stmt_close($stmt);
}
mysqli_close($con);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$city="Sandnes";
// Create a prepared statement
$stmt=mysqli_stmt_init($con);
if (mysqli_stmt_prepare($stmt,"SELECT District FROM City WHERE Name=?"))
{
// Bind parameters
mysqli_stmt_bind_param($stmt,"s",$city);
// Execute query
mysqli_stmt_execute($stmt);
// Bind result variables
mysqli_stmt_bind_result($stmt,$district);
// Fetch value
mysqli_stmt_fetch($stmt);
printf("%s is in district %s",$city,$district);
// Close statement
mysqli_stmt_close($stmt);
}
mysqli_close($con);
?>
定义和用法
mysqli_stmt_init() 函数初始化声明并返回 mysqli_stmt_prepare() 使用的对象。
语法
mysqli_stmt_init(connection);
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
技术细节
返回值: | 返回一个对象。 |
---|---|
PHP 版本: | 5+ |
PHP MySQLi 参考手册
以上内容是否对您有帮助:
更多建议: