The data taken from the results is taken out as an array.
1.PHP querying a piece of information in a database
PHP link Database/*1. Link object IP address user name password database name--*/$db =new mysqli ("localhost", "root", "123", "Zhousan");// Determine if the link is wrong Mysqli_connect_error ()? Die ("Link Failed"): "Link succeeded";//three-step operator//Prepare SQL statement $sql= "Select*from fruit";//4 Execute SQL statement return result set object $ result= $db->query ($sql);//Remove All data $rr= $result->fetch_all ();//return all data and exist in the form of a two-dimensional array var_dump ($RR);// You can also iterate through the collection (nested) or loop through the contents of the data
2. Adding information to the database via PHP
$obj =new mysqli ("localhost", "root", "123", "Zhousan"); Mysqli_connect_error () Die ("error"): print "Success"; $tt = "INSERT INTO Fruit values (' w ', ' f ', 2.1, ' SD ', 2, ' SD ') "//insert statement if the check error can be copied to the Mysqle server to see if it runs $rt= $obj->query ($TT); var_ Dump ($RT);//returns BOOL value true or false//$yy = $rt->fetch_all (); This statement cannot be executed will be error
3. Fetching data from the result set
$attr = $result->fetch_all (); All data is returned, and there are three optional arguments in the form of a two-dimensional array: Mysqli_assoc returns an associative array, Mysqli_num returns an indexed array, Mysqli_both returns an index and association, and does not need to double-quote $attr = $ when used Result->fetch_array ();//Returns the current data, returns a one-dimensional array, by default the index association has $attr = $result->fetch_assoc (); Returns the current data, returning a one-dimensional associative array $attr = $result->fetch_object (); Returns the object of the current data $attr = $result->fetch_row (); Returns the current data, returning an indexed array
4. Iterate through the collection to fetch data (note the data in while)
$connect 1=new mysqli ("localhost", "root", "123", "Zhousan"); $langu = "Select*from fruit"; $gg = $connect 1->query ($ Langu), while ($attr = $gg->fetch_row ()) {echo] <div>{$attr [0]}--{$attr [1]}--{$attr [2]}--{$attr [3]}--{$attr [4]} </div> ";}
PHP Link Database 1