Php + mysqli queries database instances using object-oriented methods, and mysqli is object-oriented. Php + mysqli use the object-oriented method to query database instances. mysqli this article describes how php + mysqli uses the object-oriented method to query databases. I would like to share with you how to use php + mysqli to query database instances in an object-oriented way.
This article describes how php + mysqli queries databases using object-oriented methods. Share it with you for your reference. The specific implementation method is as follows:
<? Php // Step 1: Create a data connection object $ mysqli = new MySQLi ("localhost", "root", "123456"); // Default MySQL class, for its attributes and methods, see the manual if ($ mysqli-> connect_error) {// connect_error is the attribute, and the error die ("database connection failed :". $ mysqli-> connect_errno. "--". $ mysqli-> connect_error); // connect_errno: Error No.} $ mysqli-> select_db ("liuyan "); // select database $ mysqli-> query ("set names 'gbk'"); // Step 2: query the database. the code is as follows: $ SQL = "select title, contents from news limit 5, 5 "; // Step 3: Execute. The result $ res = $ mysqli-> query ($ SQL) or die ($ mysqli-> error) is displayed ); // return value $ res is the resource type (the resource type of the obtained result) if ($ res) {while ($ row = $ res-> fetch_assoc () {// note: fetch_assoc () is a function in MySQLi_Result. for details, see echo "title :". $ row ['title']."
Content :". $ row ['tents']. "" ;}}// Step 4: release the result set and close the connection $ res-> free (); $ mysqli-> close ();?>
I hope this article will help you with php programming.
Examples in this article describes how php + mysqli queries a database using object-oriented methods. Share it with you...