Two methods of mysqli database connection in PHP

Source: Internet
Author: User

Mysqli is a function after php5, no extension can be opened by a friend to open your php.ini configuration file.
Look for the following statement:Extension=php_mysqli.dll Modify it to:Extension=php_mysqli.dll .
There are many new features and benefits compared to MySQL
(1) Support local binding, preparation (prepare) and other syntax
(2) Error code to execute SQL statement
(3) Execute multiple SQL simultaneously
(4) An object-oriented calling interface method is also provided.
Below one by one use PHP instance for mysqli database connection!
Use method one: Using the traditional process-oriented approach
The PHP code is as follows:

 <? php   $connect  = mysqli_connect  (' localhost ', ' Root ', ', ' volunteer ') or die  (' Unale to connect '   $sql  = "SELECT * from Vol_msg" ;   $result  = mysqli_query  ( $connect ,  $sql   while  ( $row  = mysqli_fetch_row  ( $result   echo  Span style= "COLOR: #800080" > $row  [0];} ? 

Using method Two: Invoking an interface using an object-oriented method (recommended)
Look at the PHP code as follows:

<?PHP//create the object and open the connection, and the last parameter is the name of the selected database$mysqli=NewMysqli (' localhost ', ' root ', ' ', ' volunteer '));//Check if the connection is successfulif(Mysqli_connect_errno()){    //Note Mysqli_connect_error () new features     die(' Unable to connect! ').Mysqli_connect_error();}$sql= "SELECT * FROM Vol_msg";//Execute SQL statements, fully object-oriented$result=$mysqli->query ($sql); while($row=$result-Fetch_array ()) {    Echo $row[0];}?>

The above two PHP instances run exactly the same results, and you can clearly see the benefits of building a database connection using the Mysqli class Object! Inserting and modifying records I don't have to talk about it, just change the SQL statement, next I'll talk about prepare interface features!

Http://www.phpddt.com/db/286.html

Two methods of mysqli database connection in PHP

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.