![]() |
|
|||||||
![]() |
|
|
Thread Tools | Display Modes |
|
#1
IP: 112.87.17.117
|
|||
|
|||
|
我平时一直是用mysql_fetch_array($result)函数组织数据。发现数据量大的时候速度会慢下来,不知道大家都怎么查询和显示。
听说可以把数据全部查询出来后由JS去组织,这样能把一部分负担分给客户机,这方法可行吗?哪位有这方面的资料? 下面是我常用的显示方法: $result=mysql_query('select id,username,address,phone from userlist order by id desc'); while ($rs=mysql_fetch_array($result)){ echo $rs["id"].","; echo $rs["username"].","; echo $rs["mydate"].";"; } |
|
#2
IP: 112.87.17.117
|
|||
|
|||
|
Code:
<?php
//这种方法不错.
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* prepare statement */
if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
$stmt->execute();
/* bind variables to prepared statement */
$stmt->bind_result($col1, $col2);
/* fetch values */
while ($stmt->fetch()) {
printf("%s %s\n", $col1, $col2);
}
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
它打印两种方式:一种是关联数组;一种是索引数组 如果只需要一结果的话,别用它 |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|