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 ...