Mysqli properties of object objects for extended libraries and comparison with MySQL library-oriented process

Source: Internet
Author: User

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

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.