$DBH = @mysql_connect ("localhost:3306", "root", "9999");
/* Define the 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 the strings to be sent. */
@mysql_select_db ("OK", $DBH);
/* Select a database from the MySQL server where the database name is OK */
$q = "SELECT * FROM ABC";
/* Define variable Q, "SELECT * FROM ABC" is an SQL statement that reads data from table ABC */
?>
$rs = mysql_query ($q, $DBH);
/* Define the variable RS, function mysql_query () means: Send out the query word falsify MySQL to do related processing or execution. Since PHP is executed from right to left, the value of RS is the value returned by the server running the mysql_query () function */
if (! $rs) {die ("Valid result!");}
echo "
"; echo "
Id |
Name |
"; while ($row = Mysql_fetch_row ($rs)) echo "
$row [0] |
$row [1] |
"; /* Define the Quantitative (array) row and use the while loop to write out the data one by one. The function mysql_fetch_row () means that the query result $rs single column is split into the array variable. $row [0] and $row [1] position can be changed */echo "
";
?>
$rs = mysql_query ($q, $DBH);
while ($row = Mysql_fetch_object ($rs)) echo "$row->id $row->name
";
/* ID and name can be swapped in position */
?>
$rs = mysql_query ($q, $DBH);
while ($row = Mysql_fetch_array ($rs)) echo "$row [id] $row [name]
";
/* ID and name can be swapped in position */
?>
@mysql_close ($DBH);
/* Close the connection to the MySQL database */
?>
http://www.bkjia.com/PHPjc/319005.html www.bkjia.com true http://www.bkjia.com/PHPjc/319005.html techarticle ? $dbh = @mysql_connect ("localhost:3306", "root", "9999");/* define variable Dbh,mysql_connect () function means connect MySQL database, "@" means to block error */if (! $dbh) {die ("error");} ...