首页 > 代码库 > PHP MySQL 连接数据库
PHP MySQL 连接数据库
PHP连接MySQL的小实例
<?php
/*时间:2014-09-14
*作者:葛崇
*功能:PHP连接MySQL小实例
* */
/*
SQL 脚本。直接贴到命令行运行。
DROP DATABASE gechong;
CREATE DATABASE gechong;
USE gechong
CREATE TABLE T1(
id INT(10),
name VARCHAR(10),
url VARCHAR(30));
INSERT INTO T1 VALUES (1,‘gechong1‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (2,‘gechong2‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (3,‘gechong3‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (4,‘gechong4‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (5,‘gechong5‘,‘http://www.cnblogs.com/xiaoit/‘);
*/
$con = mysql_connect("localhost","root","gechong");
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db("gechong", $con);
$result = mysql_query("SELECT * FROM t1");
echo "<table border=‘3‘ >
<tr>
<th bgcolor=#FF0000>ID</th>
<th bgcolor=#FF0000>Name</th>
<th bgcolor=#FF0000>URL</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td >" . $row[‘id‘] . "</td>";
echo "<td >" . $row[‘name‘] . "</td>";
echo "<td >" . $row[‘url‘] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
/*时间:2014-09-14
*作者:葛崇
*功能:PHP连接MySQL小实例
* */
/*
SQL 脚本。直接贴到命令行运行。
DROP DATABASE gechong;
CREATE DATABASE gechong;
USE gechong
CREATE TABLE T1(
id INT(10),
name VARCHAR(10),
url VARCHAR(30));
INSERT INTO T1 VALUES (1,‘gechong1‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (2,‘gechong2‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (3,‘gechong3‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (4,‘gechong4‘,‘http://www.cnblogs.com/xiaoit/‘);
INSERT INTO T1 VALUES (5,‘gechong5‘,‘http://www.cnblogs.com/xiaoit/‘);
*/
$con = mysql_connect("localhost","root","gechong");
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db("gechong", $con);
$result = mysql_query("SELECT * FROM t1");
echo "<table border=‘3‘ >
<tr>
<th bgcolor=#FF0000>ID</th>
<th bgcolor=#FF0000>Name</th>
<th bgcolor=#FF0000>URL</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td >" . $row[‘id‘] . "</td>";
echo "<td >" . $row[‘name‘] . "</td>";
echo "<td >" . $row[‘url‘] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
PHP MySQL 连接数据库
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。