Copy Code code as follows:
?
$DBH = @mysql_connect ("localhost:3306", "root", "000000");
/* Define variable DBH, the mysql_connect () function means to connect to the MySQL database, "@" means to block the error * *
if (! $dbh) {die ("error");}
The/* Die () function means that the string in parentheses is sent to the browser and interrupts the PHP program (Script). The arguments in parentheses are for the string to be sent out. */
@mysql_select_db ("OK", $DBH);
/* Select a database in the MySQL server, this is the selected database named OK * *
$q = "SELECT * FROM ABC";
/* Define variable Q, "SELECT * from ABC" is an SQL statement that means to read data from the table ABC * *
?>
<!--========= Method a =========-->
Copy Code code as follows:
?
$rs = mysql_query ($q, $DBH);
/* Define variable RS, function mysql_query () means: Send out query word falsify MySQL do related processing or execution. Since PHP is executed from right to left
, so the value of RS is the value returned after the server runs the mysql_query () function.
if (! $rs) {die ("Valid result!");}
echo "<table>";
echo "<tr><td>ID</td><td>Name</td></tr>";
while ($row = Mysql_fetch_row ($rs)) echo "<tr><td> $row [0]</td><td> $row [1]</td></tr > ";
/* Defines the quantity (array) row and uses the while loop to write out the data one by one.
function mysql_fetch_row () means to $rs a single column of query results into an array variable.
$row [0] and the position of the $row [1] can be changed/
echo "</table>";
?>
<!--========= Method two =========-->
Copy Code code as follows:
?
$rs = mysql_query ($q, $DBH);
while ($row = Mysql_fetch_object ($rs)) echo "$row->id $row->name <br/>";
/* ID and name can be changed to position * *
?>
<!--========= Method three =========-->
Copy Code code as follows:
?
$rs = mysql_query ($q, $DBH);
while ($row = Mysql_fetch_array ($rs)) echo "$row [id] $row [name] <br/>";
/* ID and name can be changed to position * *
?>
<!--========= Method three fastest =========-->
?
@mysql_close ($DBH);
/* Close the connection to the MySQL database * *
?>