php-accessing the database in an object-oriented manner

Source: Internet
Author: User

<?PHP//Object-oriented Access database//Build Object$DX=NewMysqli ("localhost", "root", "123", "Nation");//determine if the connection is successful/*if (Mysqli_connnect_error ()) {echo "Connection failed";    Exit ();    Die ("Connection failed"); }*/!Mysqli_connect_error() or die("Connection Failed");//Write SQL statements$sql= "SELECT * From Nation";//Execute SQL statement$result=$DX->query ($sql);//Reads data from the result set//$attr = $result->fetch_all ();//Returns all elements of the table in a two-dimensional array, with parameters Mysqli_assoc, Mysqli_num, or Mysqli_both Default return index array without parameters


$attr = $result->fetch_array ();//returns the current record as a one-dimensional array, with parameters Mysqli_assoc, Mysqli_num, or mysqli_both; returns mysqli by default without parameters _both array//$attr = $result->fetch_row ();//returns the current record as a one-dimensional array, cannot add arguments, returns an indexed array//$attr = $result->fetch_assoc ();// Returns the current record as a one-dimensional array, cannot add arguments, returns an associative array//$attr = $result->fetch_object ();//Returns an object, including an object member variable.
How to output the entire contents of a table while($attr=$result-Fetch_row ()) { Var_dump($attr);}

<?php//Object-oriented Access database//Build Object $dx=new mysqli ("localhost", "root", "123", "Nation");//Determine if the connection is successful/*if (Mysqli_connnect_error ( ) {echo "Connection failed"; exit ();//die ("Connection Failed");} */!mysqli_connect_error () or Die ("Connection Failed");//write SQL statement $sql= "SELECT * from Nation";//Execute SQL statement $result= $dx->query ($sql); /Read data from result set//$attr = $result->fetch_all ();//Returns all elements of a table in a two-dimensional array, with parameters Mysqli_assoc, Mysqli_num, or Mysqli_both No parameter returns the indexed array by default//$attr = $result->fetch_array ();//returns the current record as a one-dimensional array, with parameters Mysqli_assoc, Mysqli_num, or Mysqli_both No parameter returns the Mysqli_both array by default//$attr = $result->fetch_row ();//returns the current record as a one-dimensional array, cannot add arguments, returns an indexed array//$attr = $result FETCH_ASSOC ();//returns the current record as a one-dimensional array, cannot add arguments, returns an associative array//$attr = $result->fetch_object ();//Returns an object, including an object member variable.
The way to output the entire contents of the table while ($attr = $result->fetch_row ()) {var_dump ($attr);}

php-accessing the database in an object-oriented manner

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.