我是一个完整的数据库新手.到目前为止,我知道我可以使用PHP的mysql_connect()命令连接到MySQL,但是除此之外,我真的不知道如何获取这些数据并将其放到网页上.
a)除mysql_connect()外还有其他方法
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'].'
';
echo $row['field2'];
}
?>
检出mysql_fetch_assoc mysql_fetch_array和mysql_fetch_object
这是非常基础的知识,您将需要搜索教程.有很多关于.
标签:mysql,php,database
来源: https://codeday.me/bug/20191210/2098069.html