mysql数据库网页_如何将MySQL数据库实现到网页中?

bd96500e110b49cbb3cd949968f18be7.png

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) are there ways other than mysql_connect()

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'].'
';

echo $row['field2'];

}

?>

Check out mysql_fetch_assoc mysql_fetch_array and mysql_fetch_object

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值