This article mainly introduces how to use Preprocessing Technology for database query in php + mysqli. The example shows how to use Preprocessing Technology in php + mysqli. For more information, see
This article mainly introduces how to use Preprocessing Technology for database query in php + mysqli. The example shows how to use Preprocessing Technology in php + mysqli. For more information, see
This example describes how to use Preprocessing Technology to query databases in php + mysqli. 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.