Several methods of reading database information in PHP _php tutorial

Source: Internet
Author: User
$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 " "; while ($row = Mysql_fetch_row ($rs)) echo " "; /* 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 "
Id Name
$row [0] $row [1]
";
?>





$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");} ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.