Home > Backend Development > PHP Tutorial > Several methods for reading database information in PHP_PHP tutorial

Several methods for reading database information in PHP_PHP tutorial

WBOY
Release: 2016-07-21 15:52:00
Original
1391 people have browsed it

$dbh = @mysql_connect("localhost:3306","root","9999");
/* Define the variable dbh, the mysql_connect() function means to connect to the mysql database, "@" It means to block error */
if(!$dbh){die("error");}
/* The die() function means to send the string in brackets to the browser and interrupt PHP Script. The parameters in brackets are the string to be sent. */
@mysql_select_db("ok", $dbh);
/* Select a database in the mysql server. The database name selected here is ok */
$q = "SELECT * FROM abc" ;
/* Define variable q, "SELECT * FROM abc" is a SQL statement, which means reading the data in table abc */
?>





$rs = mysql_query($q, $dbh);
/* Define the variable rs, the function mysql_query() means: send the query string for MySQL to do related processing or execution. Since PHP is executed from right to left, so, The value of rs is the value returned by the server after running the mysql_query() function */
if(!$rs){die("Valid result!");}
echo "

";
echo "";
while($row = mysql_fetch_row($rs)) echo "$row[0]";
/* Define the quantitative variable (array) row and use while loop, write out the data one by one.
The function mysql_fetch_row() means: split the query result $rs single column into array variables.
$row[0] and $row[1] can be positioned Change*/
echo "
IDName
$row[1]
";
?>





$rs = mysql_query($q, $dbh);
while($row = mysql_fetch_object($rs)) echo "$row->id $row->name
";
/* id and name can change positions */
?>





$rs = mysql_query($q, $dbh);
while($row = mysql_fetch_array($rs)) echo "$row[id] $row[name]
";
/* ID and name can be changed */
?>

@mysql_close($dbh);
/* Close the connection to the mysql database */
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319005.htmlTechArticle? $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 error reports*/ if(!$dbh){die("error");}...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template