php-如何将MySQL数据库实现到网页中?

前端之家收集整理的这篇文章主要介绍了php-如何将MySQL数据库实现到网页中? 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我是一个完整的数据库新手.到目前为止,我知道我可以使用PHPMysqL_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'].'<br />'; 
    echo $row['field2'];
}
?>

检出MysqL_fetch_assoc MysqL_fetch_array和MysqL_fetch_object

这是非常基础的知识,您将需要搜索教程.有很多关于.

原文链接:https://www.f2er.com/mysql/532129.html

猜你在找的MySQL相关文章