Home > php教程 > php手册 > body text

PHP 查询MySQL数据库的完整代码

WBOY
Release: 2016-06-13 11:37:22
Original
2071 people have browsed it

PHP 查询MySQL数据库的完整代码,使用时请注意修改连接语句中的用户名与密码。

$link = mysql_connect('localhost', 'root', '123456')  //烈火提示:请先修改用户名与密码
or die('Could not connect: ' . mysql_error());
mysql_select_db('ruida') or die('Could not select database');

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

// 用 HTML 显示结果
echo "

\n";
while ($line = mysql_fetch_assoc($result)) {
echo "\t\n";
foreach ($line as $col_value) {
echo "\t\t\n";
}
echo "\t\n";
}
echo "
$col_value
\n";
// 释放结果集
mysql_free_result($result);
// 关闭连接 Liehuo.Org
mysql_close($link);
?>
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template