<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><?php//Build a connection to create a Connection object $db = new mysqli ("localhost", "root", "123", "mydb");//Determine if error/*if (Mysqli_connect_error ()) {echo "Connection Failed! "; Exit;} */mysqli_connect_error () Die ("Connection Failed"): "";//write SQL statement $sql = "SELECT * from Info";//Execute SQL statement, return result set Object $reslut = $db->query ( $sql);//Read data from result set, return array//$attr = $reslut->fetch_all (); Reads all data, returns the index two-dimensional array//$attr = $reslut->fetch_array (); Reads the data pointed to by the current pointer, returns an array of index associations that exist//$attr = $reslut->fetch_assoc (); Returns an associative array//$attr = $reslut->fetch_row (); Returns an indexed array//$attr = $reslut->fetch_object (); Returns the object/* $arr = Array (), while ($attr = $reslut->fetch_row ()) {Array_push ($arr, $attr);} Var_dump ($arr); * *?></Body></HTML>
Here's another
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><?php//Connect Object $db = new mysqli ("localhost", "root", "123", "mydb");//write SQL statement $sql = "INSERT into info values (' p003 ', ' Zhang San ', ' 1 ', ' n001 ', ' 1990-2-3 ');//Execute SQL statement $result = $db->query ($sql);/*if ($result) {echo "executed successfully! ";} else{echo "Execution failed! ";} *///$result->fetch_row ();?></Body></HTML>
PHP Data Access