Home >Backend Development >PHP Tutorial >php+mysqli uses preprocessing technology to perform database queries, mysqli preprocessing_PHP tutorial

php+mysqli uses preprocessing technology to perform database queries, mysqli preprocessing_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:501074browse

php+mysqli uses preprocessing technology for database query, mysqli preprocessing

The example in this article describes how php+mysqli uses preprocessing technology to perform database queries. Share it with everyone for your reference. The details are as follows:

The code is a bit difficult and requires solid basic knowledge to be easily understood. Here is the code first:

Here is how to query the id, title, and contents values ​​of all id>5:

Copy code The code is as follows:
$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 result set
$mysqli_stmt->bind_result($id,$title,$contents);
//Execute
$mysqli_stmt->execute();
//Get 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 be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/949460.htmlTechArticlephp+mysqli uses preprocessing technology to perform database queries, mysqli preprocessing This article describes the use of php+mysqli Preprocessing technology is a method for database query. Share it with everyone...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn