PHP mysqli_stmt_init() 函數(shù)
PHP MySQLi 參考手冊
實例
初始化聲明并返回 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);
?>
定義和用法
mysqli_stmt_init() 函數(shù)初始化聲明并返回 mysqli_stmt_prepare() 使用的對象。
語法
mysqli_stmt_init(connection);
參數(shù) | 描述 |
connection | 必需。規(guī)定要使用的 MySQL 連接。 |
技術細節(jié)
PHP MySQLi 參考手冊
更多建議: