The function of this code is:
Connect to a MySQL server with a URL address of localhost and a port of 3306. The MySQL server account is "root" and the password is "9999". There is a database OK on the MySQL server and there is a table ABC in the database. Table ABC is a total of two columns, the column name is "id" and "name", the ABC of all the data read out.
The following is the referenced content:
$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"; Web Teaching Network http://www.webjx.com
/* 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 variable (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 is split into the array variable. The position of the $row [0] and the $row [1] 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/486621.html www.bkjia.com true http://www.bkjia.com/PHPjc/486621.html techarticle The function of this code is to connect to a MySQL server with a URL address of localhost and a port of 3306. The MySQL server account is "root" and the password is "9999". The MySQL server has ...