Object-oriented way to access database build object to determine whether the connection is error (two ways) write SQL statement Execute SQL statement read data loop output from result set Object $db = new mysqli ("localhost", "root", "" "," Z-stu ");//Method one if (Mysqli_connect_error ()) {echo "connection error"; Exit;} Method two!mysqli_connect_error () or Die ("Connection failed! $sql = "SELECT * from info"; $result = $db->query ($sql);//Method one while ($atr = $result->fetch_row ()) {}//method two $atr = $res Ult->fetch_all (); foreach ($atr as $v) {echo $v [0];} Reads data from the result set object $attr = $result->fetch_all (mysqli_both); Returns all data as a two-dimensional array $attr = $result->fetch_array (); Returns the data that the current pointer points to, whether the default index can be an index or an association, or a combination of $attr = $result->fetch_assoc (); Returns the data (associative array) pointed to by the current pointer $attr = $result->fetch_object (); Return object $attr = $result->fetch_row (); Returns an indexed array
Object-oriented way to access the database