如何将MySQL数据库实现到网页中? [英] How does one implement a MySQL database into a webpage?

查看:693
本文介绍了如何将MySQL数据库实现到网页中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个完整的数据库新手.到目前为止,我知道我可以使用PHP的mysql_connect()命令连接到MySQL,但是除此之外,我真的不知道如何获取这些数据并将其放到网页上.

I am a complete database newbie. So far, I know that I can connect to MySQL using PHP's mysql_connect() command, but apart from that, I really don't see how to take that data and put it onto a web page.

a)mysql_connect()以外的其他方法

a) are there ways other than mysql_connect()

b)可以说我在mysql中有一个数据表,而我想要的只是该表(例如:名称和电话号码的列表)现在显示在我的网页上.我一辈子都找不到适合自己的教程.

b) lets say I had a table of data in mysql and all I wanted was for that table (for example: list of names and telephone numbers) to now appear on my web page. I can't for the life of me find a tutorial for this.

推荐答案

<?
$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_arraymysql_fetch_object

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

This is the very basics, you will want to search for tutorials. There are many about.

这篇关于如何将MySQL数据库实现到网页中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆