标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php //连接参数 $host = "localhost" ; $user = "root" ; $pwd = "111111" ; $db = "test" ; $mysqli = new mysqli( $host , $user , $pwd , $db ); //实例化一个mysqli对象,并打开一个连接 if (mysqli_connect_errno()){ //检查是否可以正确打开数据库 echo "<font color=‘red‘>unable to connect!</font>" ; } $SQL_SELECT_SYMBOLS = "select * from symbols" ; if ( $result = $mysqli ->query( $SQL_SELECT_SYMBOLS )){ if ( $result ->num_rows>0){ echo ‘<table cellpadding="10" border="1">‘ ; echo ‘<tr><th>id</th><th>country</th><th>animal</th><th>cname</th></tr>‘ ; while ( $arr = $result ->fetch_array()){ echo "<tr>" ; echo "<td>" . $arr [0]. "</td>" ; echo "<td>" . $arr [1]. "</td>" ; echo "<td>" . $arr [2]. "</td>" ; echo "<td>" . $arr [3]. "</td>" ; echo "</tr>" ; } echo "</table>" ; } else { echo "记录未找到!" ; } $result ->close(); //释放记录集所占用的内存 } else { echo "error in query:$query." . $mysqli ->error; } $mysqli ->close(); //关闭数据库连接 ?> |
标签:
原文地址:http://www.cnblogs.com/webenh/p/5655692.html