Php+mysqli querying database instances using object-oriented methods, Mysqli object-oriented _php tutorials

Source: Internet
Author: User

Php+mysqli querying DB instances using object-oriented methods, mysqli object-oriented


The examples in this article describe how Php+mysqli uses object-oriented methods to query a database. Share to everyone for your reference. The implementation method is as follows:

<?php//First step: Create data Connection object $mysqli = new mysqli ("localhost", "root", "123456");//Default MySQL class, its properties and methods see Manual if ($mysqli- Connect_error) {//connect_error is a property, error die ("Database connection failed:". $mysqli->connect_errno. " --". $mysqli->connect_error);//Connect_errno: Error number} $mysqli->select_db (" Liuyan ");//Select Database $mysqli->query (" Set names ' GBK ');//Second step: Database query, code as follows $sql = "Select title,contents from News limit 5,5";//Third step: Execute, show result $res = $mysqli->quer Y ($sql) or Die ($mysqli->error);//The return value $res to the resource type (the resource type that gets the result) if ($res) {while ($row = $res->fetch_assoc ()) {// Note: Fetch_assoc () is a function in Mysqli_result, see the Manual echo "title:" in the details. $row [' title '].
Content: ". $row [' contents ']."; }}//Fourth step, release result set, close connection $res->free (); $mysqli->close (); >

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/949453.html www.bkjia.com true http://www.bkjia.com/PHPjc/949453.html techarticle Php+mysqli querying a DB instance using object-oriented approach, MYSQLI object-oriented This article describes Php+mysqli method of querying a database using object-oriented methods. Share to everyone ...

  • Related Article

    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.