Php + mysqli using Preprocessing Technology for database queries

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.