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.