Home > Backend Development > PHP Tutorial > Complete code for querying MySQL database with PHP_PHP tutorial

Complete code for querying MySQL database with PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:22:27
Original
1278 people have browsed it

The complete code of PHP querying MySQL database

The complete code of PHP querying MySQL database. Please pay attention to modifying the username and password in the connection statement when using it.

$link = mysql_connect('localhost', 'root', '123456') //Rainfire Tip: Please change the username and password first
or die('Could not connect: ' . mysql_error());
mysql_select_db('ruida') or die('Could not select database');

//Execute SQL query
$query = 'SELECT * FROM product';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Display results using HTML
echo "

n";
while ($line = mysql_fetch_assoc($result)) {
echo "tn";
foreach ($line as $col_value) {
echo "ttn";
}
echo "tn";
}
echo "
$col_value
n";
// Release the result set
mysql_free_result($result);
// Close the connection Liehuo.Org
mysql_close($link);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/848319.htmlTechArticleThe complete code of PHP querying MySQL database PHP The complete code of querying MySQL database, please pay attention to modifying the connection statement when using it Username and password. ?php $link = mysql_connect('localho...
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