1、数据库连接文件:conn.php(连接MYSQL数据库的配置文件) |
<? //本文件是数据库连接的配置文件,连接参数在此定义 $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"); mysql_free_result($result);//free the resource at the end |
3、数据库查询文件:selectdb.php(数据库查询,对结果的显示 ) |
<?php //演示如何查询数据库 include("conn.php"); /* 执行 SQL 查询 */ $query = "SELECT * FROM my_table"; $result = mysql_query($query) or die("Query failed"); /* 在 HTML 中打印结果 */ /* 释放资源 */ /* 断开连接 */ |
4、数据库操纵文件:operatedb.php(数据库记录的增加、删除、修改 ) |
<? //演示了如何对数据库中的数据进行插入,删除和更新操作 include("conn.php"); $sql="insert into user (ID,PW,Name,Sex,Email,Title,Info) values ('$userid','$userpw','$usernam $sql="delete from user where ID='$userid'"; //删除语句 $sql="update user set PW='$userpw',Name='$username',Sex='$usersex',Email='$usermail',
?> |
5、文件操作程序:fileoperate.php (最常用的文件操作) |
<? $filename="****";//要操作的文件名 //读操作,读出一个文件所有内容到一个字符串变量中 //再将该字符创串的内容写入原来的文件中 //追加到文件末尾 //删除文件 |