The mysqli_stmt_init() function initializes a statement and returns an object suitable for mysqli_stmt_prepare().
PHP mysqli_stmt_init() Function has the following syntax.
mysqli_stmt_init(connection);
Returns an object.
<?php//from ww w .j a v a 2s. c o m
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$city="New York";
$stmt=mysqli_stmt_init($con);
if (mysqli_stmt_prepare($stmt,"SELECT District FROM City WHERE Name=?")){
mysqli_stmt_bind_param($stmt,"s",$city); // Bind parameters
mysqli_stmt_execute($stmt); // Execute query
mysqli_stmt_bind_result($stmt,$district); // Bind result variables
mysqli_stmt_fetch($stmt); // Fetch value
print $district;
mysqli_stmt_close($stmt);
}
mysqli_close($con);
?>