例
初始化語句,並返回一個對象與使用mysqli_stmt_prepare()
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
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參考