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);
?>