Three different ways:
1. Function mode: Out of date
2. Object-oriented approach: MYSQLI class, support MySQL database.
3.PDO mode: Supports other databases.
. Object-oriented approach: Mysqli class
//1. Creating a Connection object//$db = new mysqli ("localhost", "root", "123", "MyDB"),//2. Determine if the current connection is correct//if (Mysqli_connect_error ()) {// echo "Connection failed! "; EXIT;//}//3. Write an SQL statement//$sql = "SELECT * from Info";//4. Executes the SQL statement if a result set object is returned successfully//$result = $db->query ($sql);//5. Read Query Results//if ($result) {//Read all data from the result set object, return a two-dimensional array//$arr = $result->fetch_all (); Reads the data from the result set, reads one bar at a time, returns a one-dimensional array (the Index association has)//$arr = $result->fetch_array (); Reads the data from the result, reads one bar at a time, returns a one-dimensional Array (association)//$arr = $result->fetch_assoc (); Reads the data from the result, reads one bar at a time, returns an object//$arr = $result->fetch_object (); Reads the data from the result, reads one bar at a time, returns a one-dimensional array (index)//$arr = $result->fetch_row (); /*while ($arr = $result->fetch_row ()) {var_dump ($arr); }*///}/* $db = new mysqli ("localhost", "root", "123", "MyDB"); Mysqli_connect_error ()? Die ("Connection failed!") "):" "; $sql =" Delete from Nation where code= ' n006 ' "; if ($db->query ($sql)) {echo" Delete succeeded! ";} else{echo "Delete failed! ";} */?> Example:<Tablewidth= "100%"Border= "1"cellpadding= "0"cellspacing= "0"> <TR> <TD>Code</TD> <TD>Name</TD> <TD>Gender</TD> <TD>National</TD> <TD>Birthday</TD> </TR> <?php $db = new mysqli ("localhost", "root", "123", "MyDB"); $sql = "SELECT * from Info"; $result = $db->query ($sql); if ($result) {$arr = $result->fetch_all (); foreach ($arr as $v) {echo <tr> <td>{$v [0]}</td> <td>{$v [1]}</td> <td>{$v [2]}</td> <td>{$v [3]}</td> <td>{$v [4]}</td> </tr> " ; } } ?> </Table></Body></HTML>
PHP data Access (Object oriented approach: Mysqli Class)