<?
//本文件是数据库连接的配置文件,连接参数在此定义
$host="localhost";
$user="******";//you need modify here,replace your database's account
$passwd="******";//also modify here,replace your database's password
$dbname="******";//and modify here,replace your database's name if(!$link=mysql_connect("$host", "$user", "$pwd")) //start connect your database
{
print 'Could not connect to database';
exit;
}
mysql_select_db("$dbname") or die("Could not select database");
?>
2、数据库列表文件:list_alltb.php(列出数据库中所有表格名称)
<?
//演示了如何列出一个数据库的所有表
include("conn.php");
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
exit;
}
$i=0;
echo "数据库$dbname中有表如下:<br>";//the code below start tolist all the tables in the database";
echo "<table border=1>";
while ($i<mysql_num_rows($result)) {
$tb_names[$i] = mysql_tablename ($result, $i);
echo "<tr><td>$tb_names[$i]</td></tr>\n";
$i++;
}
echo "</table>";
mysql_free_result($result);//free the resource at the end
?>
<?
//演示了如何对数据库中的数据进行插入,删除和更新操作 include("conn.php");
$sql="insert into user (ID,PW,Name,Sex,Email,Title,Info) values ('$userid','$userpw','$usernam
e','$usersex','$usermail','$usertitle','$userinfo')";//插入语句
mysql_query($sql) or die(mysql_error());//执行插入操作
$sql="delete from user where ID='$userid'"; //删除语句
mysql_query($sql) or die(mysql_error()); //执行删除操作
$sql="update user set PW='$userpw',Name='$username',Sex='$usersex',Email='$usermail',
Title='$usertitle',Type='$usertype',Info='$userinfo' where ID='$userid'"; //更新语句
mysql_query($sql) or die(mysql_error()); //执行删除操作