庸医

Whatever comes our way,whatever battle we have raging inside us,we always have a choice. My friend Harry taught me that.He chose to be the best of himself.It's the choices that make us who we are and we can always choose to do what's right.

导航

PHP学习笔记之二:在PHP中连接MySQL

创建如下脚本文件:dbconnect.php

<?php

$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "123456";
$dbdatabase = "productsdb";

$db = mysql_connect($dbhost, $dbuser, $dbpassword); //数据库连接操作,将连接结果保存到$db变量中
mysql_query("SET NAMES 'GBK'");  //设置查询结果为中文
mysql_select_db($dbdatabase, $db); //选择使用的数据库

$sql = "SELECT * FROM products;";
$result = mysql_query($sql); //将SQL语句发送到数据库,并将查询结果放到$result变量中

while($row = mysql_fetch_assoc($result)) //mysql_fetch_assoc从$result中取出每一行记录并将其赋予$row变量
{
 echo $row['product'].'<br />';
}

?>

posted on 2008-12-14 22:25  庸医  阅读(169)  评论(0编辑  收藏  举报