The object attributes of the MySqli extension Library and the process-oriented comparison with the mysql database.

Source: Internet
Author: User

The object attributes of the MySqli extension Library and the process-oriented comparison with the mysql database.

After learning the mysql database to operate mysql, this is a process-oriented method. However, object-oriented is the trend of the times, and the mysqli extension library must be learned, as a class library, mysqli performs operations in an object-oriented manner. Therefore, this solution is better, I specifically compared it with the mysqli extension Library:

The following is the mysql database connection, query statement, return result, and resource release process:

<Pre name = "code" class = "php"> <pre name = "code" class = "php"> <? Php // 1: connect to the database $ con = mysql_connect ("localhost", "root", "toor"); // if no connection is successful, an error is returned if (! $ Con) {echo "connection failed"; exit () ;}// 2: select the database mysql_select_db ("test") to operate; // 3: send the SQL command mysql_query ("set names utf8"); // set the query encoding $ SQL = "select * from test1"; $ res = mysql_query ($ SQL, $ con ); // 4: returned results (returned by row traversal) while ($ row = mysql_fetch_row ($ res )) {echo "$ row [0] ------------- $ row [1] ----------- $ row [2] ----------- $ row [3] ----------- $ row [4]". '<br/>';} // 5: Release the resource and close the connection mysql_free_result ($ res); mysql_close ($ con);?>

 
 
The following is the connection, query statement, return result, and resource release process of mysqli extension Library:
<Pre name = "code" class = "php"> <? Php // create a mysqli object and instantiate $ mysqli = new MySQLi ("localhost", "root", "toor", "test"); if ($ mysqli-> connect_error) {die ("connection failure error message :". $ mysqli-> connect_error);} else {echo "connection successful <br/>" ;}// operate the database and send SQL $ SQL = "select * from test. test1 "; $ res = $ mysqli-> query ($ SQL); // return result while ($ row = $ res-> fetch_row ()) {foreach ($ row as $ key => $ value) {echo $ value. "";} echo "<br/>";} // var_dump ($ res); // close the resource $ res-> free (); // close the connection $ mysqli-> close ();?>

It can be clearly seen that the object-oriented mysqli is not only going further on the mind, but also relatively simple in terms of Code complexity. Therefore, I think, after learning the mysql database, it is necessary to learn the mysqli extension library.
 

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.