<?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