After learning MySQL library to operate MySQL way, this is a process-oriented approach, but, object-oriented is the general trend, Mysqli Extension Library has to learn the necessary, mysqli as a class library, when we use the object-oriented way to operate, so, This kind of scheme is better, for this reason, I have made a corresponding comparison between it and the mysqli extension library:
Here is the MySQL library connection, the query statement, the return result, the process of releasing the resource:
<pre name= "code" class= "PHP" ><pre name= "code" class= "PHP" ><pre name= "code" class= "PHP" ><pre name = "code" class= "PHP" ><?php //1: Connect to Database $con =mysql_connect ("localhost", "root", "Toor"); If there is no connection successful error if (! $con) { echo "Connection failed"; Exit (); } 2: Select the database to operate mysql_select_db ("test"); 3: Send SQL command mysql_query ("Set names UTF8");//Set query encoding $sql = "Select *from test1"; $res =mysql_query ($sql, $con); 4: Returns the result (returned by row traversal) while ($row =mysql_fetch_row ($res)) { echo "$row [0]-------------$row [1]-----------$row [ 2]-----------$row [3]-----------$row [4] "." <br/> '; } 5: Release resources, close connection mysql_free_result ($res); Mysql_close ($con); ? >
The following is the process of mysqli extension libraries, querying statements, returning results, and freeing resources:
<pre name= "code" class= "PHP" ><?php//create mysqli object, instantiate $mysqli= new mysqli ("localhost", "root", "Toor", "Test"); if ($mysqli->connect_error) {die ("Connection failed error message:" $mysqli->connect_error);} Else{echo "Connection Success <br/>";} Operation database, sending 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 Resource $res->free ();//close connection $mysqli->close (); >
Can be clearly seen, object-oriented mysqli not only in the ideological further, but also in the complexity of the code is relatively simple, therefore, I think, after learning the MySQL library, then learn mysqli extension library is very necessary
Mysqli properties of object objects for extended libraries and comparison with MySQL library-oriented process