This article mainly introduces how php + mysqli uses preprocessing technology to query databases. The example shows how to use php + mysqli preprocessing technology, for more information about how to use preprocessing technology to query databases, see the example in this article. Share it with you for your reference. The details are as follows:
The code is somewhat difficult and requires a solid foundation of knowledge for better understanding. put the code first:
Here, we can query the values of id> 5, title, and contents:
The code is as follows:
<? Php
$ Mysqli = new MySQLi ("localhost", "root", "123456", "liuyan ");
If (! $ Mysqli ){
Die ($ mysqli-> error );
}
// Create a predefined object? Placeholder
$ SQL = "select id, title, contents from news where id>? ";
$ Mysqli_stmt = $ mysqli-> prepare ($ SQL );
$ Id = 10;
// Bind parameters
$ Mysqli_stmt-> bind_param ("I", $ id );
// Bind the result set
$ Mysqli_stmt-> bind_result ($ id, $ title, $ contents );
// Execute
$ Mysqli_stmt-> execute ();
// Retrieve the bound result set
While ($ mysqli_stmt-> fetch ()){
Echo "-- $ id -- $ title -- $ contents --";
}
// Close the result set
$ Mysqli_stmt-> free_result ();
$ Mysqli_stmt-> close ();
$ Mysqli-> close ();
?>
I hope this article will help you with php programming.