我是一个完整的数据库新手.到目前为止,我知道我可以使用PHP的MysqL_connect()命令连接到MysqL,但是除此之外,我真的不知道如何获取这些数据并将其放到网页上.
b)假设我在MysqL中有一个数据表,而我想要的只是该表(例如:名称和电话号码的列表)现在显示在我的网页上.我一生都找不到适合自己的教程.
最佳答案
<?
$database_name = "dbname";
$MysqL_host = "localhost"; //almost always 'localhost'
$database_user = "dbuser";
$database_pwd = "dbpass";
$dbc = MysqL_connect($MysqL_host,$database_user,$database_pwd);
if(!$dbc)
{
die("We are currently experiencing very heavy traffic to our site,please be patient and try again shortly.");
}
$db = MysqL_select_db($database_name);
if(!$db)
{
die("Failed to connect to database - check your database name.");
}
$sql = "SELECT * FROM `table` WHERE `field`= 'value'";
$res = MysqL_query($sql);
while($row = MysqL_fetch_assoc($res)) {
// code here
// access variables like the following:
echo $row['field'].'<br />';
echo $row['field2'];
}
?>
检出MysqL_fetch_assoc MysqL_fetch_array和MysqL_fetch_object
这是非常基础的知识,您将需要搜索教程.有很多关于.