| <?php | 查询数据库的五个步骤: | |
| $connection=mysql_connect("localhost","username","password"); | 1 连接服务器:mysql_connect(), | 执行与运行命令解释器相等的功能 |
| mysql_select_db("winestore",$connection); | 2 选择数据库:mysql_select_db, | 提供了数据库指令use |
| $result=mysql_query("select * from wine",$connection); | 3 查询数据库:mysql_query() | 执行SQL查询 |
| while($row=mysql_fetch_array($result,MYSQL_NUM)){ | 4 检索结果的记录:mysql_fetch_array() | 检索解释器返回的结果集 |
| foreach($row as $attribute) | 5 处理字段值:foreach+print. | |
| print "{$attribute}"; | ||
| Print "\n"; | ||
| } | ||
| ?> | ||
| 使用mysql_fetch_field()加上<table>标签可以格式化查询结果; |