写了个php+mysql的最简单应用,实现了php连接数据库,并读取数据最基本的操作,希望对新手有用。
以下为引用的内容: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>php操作mysql数据库简单示例 by www.phperz.com</title> </head> <body> <?php $db = mysql_connect("localhost","root","password"); //连接数据库 mysql_select_db("test",$db); //选择要操作的数据库 $sql = "select * from testa"; //构造查询语句 $re = mysql_query($sql,$db); //执行查询 while($row=mysql_fetch_array($re)){ //循环输出数据 print_r($row); //打印出来 } mysql_close($db); ?> </body> </html> |
运行结果如下:
Array
(
[0] => 1
[id] => 1
[1] => 1,3,4,5,6
[type] => 1,3,4,5,6
)
Array
(
[0] => 2
[id] => 2
[1] => 14,15,16,17
[type] => 14,15,16,17
)
Array
(
[0] => 3
[id] => 3
[1] => 1,2,3,4
[type] => 1,2,3,4
)