php mysql_query php查询数据集的几种方式(mysql_unbuffered_query()与mysql_query()的区别)

php mysql_query php查询数据集的几种方式(mysql_unbuffered_query()与mysql_query()的区别)

php操作数据集几种方式

一、        ry()

一边查询一边给出结果,不缓存在页面当中php mysql_query,适合大数据处理,使用完成后php mysql_query,就自动销毁数据集.

不能再使用($,count)重新定位数据集中游标的启示位置。ry查询的结果集中php mysql_query php查询数据集的几种方式(mysql_unbuffered_query()与mysql_query()的区别),类似处理过程中,不可以使用获取结果集行数。ry查询的结果集中php mysql_query,类似处理过程完成后,可以使用获取结果集行数。之后再次操作使用类似的函数操作数据集,将没有数据集行数为0,将不输出。

二、        ()

查询结果出来全部放在缓存里面,实用于数据量小的方便操作。

类似的函数在操作过程中还是操作完成后,都可以获得正确的数据行数。($,count)可以在任意位置操作数据集的下表。($);清除内存中的查询集后,同ry()。

demo:

列子:标红部分为关键比较代码

  1 <?php
  2 
  3  
  4 
  5 /*
  6 
  7  * 连接数据库
  8 
  9  * 固定不变的量,就直接用变量例如$mysql_host,变化的量例如$this->$mysql_dbname,表示当前调用者的dbname
 10 
 11  */
 12 
 13  
 14 
 15 header("Content-Type:text/html;charset=utf-8");
 16 
 17  
 18 
 19  class DbConn{
 20 
 21    
 22 
 23     private $mysql_host;//连接的主机
 24 
 25     private $mysql_user;
 26 
 27     public $mysql_pwd;
 28 
 29     private $mysql_language;//数据库编码语言
 30 
 31     private $mysql_conn;//Mysql连接对象
 32 
 33     private $db_select; //选择的数据库对象
 34 
 35    
 36 
 37     public $mysql_dbname;//选择要连接的数据库
 38 
 39     public $sqlstr;//sql语句
 40 
 41     public $error;//错误信息提示
 42 
 43    
 44 
 45     function DbConn(){
 46 
 47         $this->mysql_host ="localhost";
 48 
 49         $this->mysql_user="root";
 50 
 51         $this->mysql_pwd="sasa";
 52 
 53         $this->mysql_language="UTF8";
 54 
 55         $this->mysql_conn=NULL;
 56 
 57         $this->db_select=NULL;
 58 
 59         $this->sqlstr="";
 60 
 61       
 62 
 63     }
 64 
 65    
 66 
 67     //设置错误信息
 68 
 69     private  function SetError($errormsg)
 70 
 71     {
 72 
 73         $this->error+="
"+$errormsg; 74 75 } 76 77 78 79 public function ShowError() 80 81 { 82 83 return $this->error; 84 85 } 86 87 88 89 90 91 //连接mysql 92 93 public function Connect() 94 95 { 96 97 $this->mysql_conn = mysql_connect($this->mysql_host, $this->mysql_user,$this->mysql_pwd) or die("mysql连接错误"); //mysql连接 98 99 $this->SetError(mysql_error()); 100 101 //选择连接的数据库名 102 103 $this->db_select = mysql_select_db($this->mysql_dbname) or die("数据库无权限或数据库选择错误"); 104 105 $this->SetError(mysql_error()); 106 107 mysql_query("set names 'utf8'"); //编码转化 108 109 } 110 111 112 113 //关闭连接 114 115 public function CloseCon() 116 117 { 118 119 mysql_close($this->mysql_conn); 120 121 } 122 123 124 125 //查询方法 126 127 public function SelectAll() 128 129 { 130 131 $result = mysql_query($this->sqlstr,$this->mysql_conn); 132 133 if($result) 134 135 { 136 137 // $result_row = mysqli_fetch_array($result); 138 139 // mysql_fetch_row() 将返回结果集中的下一行,如果没有更多行则返回 FALSE。 140 141 // mysql_fetch_array() 将返回结果集中的键值或者数组,如果没有更多行则返回 FALSE。 142 143 while($result_row= mysql_fetch_array($result)) 144 145 { 146 147 $userid=$result_row["userid"]; 148 149 $username=$result_row["username"]; 150 151 $userpwd=$result_row["userpwd"]; 152 153 $useremail=$result_row["useremail"]; 154 155 156 157 echo ""; 158 159 echo "用户名id:$userid"; 160 161 echo "用户名:$username"; 162 163 echo "密码:$userpwd"; 164 165 echo "邮箱:$useremail"; 166 167 echo ""; 168 169 echo "
"; 170 171 172 173 //mysqli_free_result($result);清除内存中的查询集 174 175 } 176 177 } 178 179 } 180 181 182 183 //大数据查询验证两种查询数据集的区别 184 185 public function Select() 186 187 { 188 189 //分别取消 mysql_unbuffered_query和mysql_query查看效果 190 191 $result = mysql_unbuffered_query($this->sqlstr, $this->mysql_conn); 192 193 //$result = mysql_query($this->sqlstr, $this->mysql_conn); 194 195 196 197 if($result) 198 199 { 200 201 // $result_row = mysqli_fetch_array($result); 202 203 // mysql_fetch_row() 将返回结果集中的下一行,如果没有更多行则返回 FALSE。 204 205 // mysql_fetch_array() 将返回结果集中的键值或者数组,如果没有更多行则返回 FALSE。 206 207 while($result_row= mysql_fetch_array($result)) 208 209 { 210 211 $userid=$result_row["userid"]; 212 213 $username=$result_row["username"]; 214 215 $userpwd=$result_row["userpwd"]; 216 217 $useremail=$result_row["useremail"]; 218 219 220 221 echo ""; 222 223 echo "用户名id:$userid"; 224 225 echo "用户名:$username"; 226 227 echo "密码:$userpwd"; 228 229 echo "邮箱:$useremail"; 230 231 echo ""; 232 233 echo "
"; 234 235 echo "处理过程中数据集总行数获取:"; 236 237 //mysql_unbuffered_query查询的结果集中,mysql_fetch_array处理过程中,不可以使用mysql_num_rows获取结果集行数 238 239 echo mysql_num_rows($result); 240 241 echo "
"; 242 243 244 245 } 246 247 mysql_data_seek($result,1);//把指针指向数据集最开始 248 249 //mysql_unbuffered_query查询的结果集中,mysql_fetch_array处理过程完成后,可以使用mysql_num_rows获取结果集行数 250 251 echo "处理完成后,数据集总行数获取:"; 252 253 echo mysql_num_rows($result); 254 255 echo "
"; 256 257 258 259 260 261 //再次操作mysql_unbuffered_query查询的结果集,数据集为空不输出 262 263 while($result_row= mysql_fetch_array($result)) 264 265 { 266 267 $userid=$result_row["userid"]; 268 269 $username=$result_row["username"]; 270 271 $userpwd=$result_row["userpwd"]; 272 273 $useremail=$result_row["useremail"]; 274 275 276 277 echo ""; 278 279 echo "用户名id:$userid"; 280 281 echo "用户名:$username"; 282 283 echo "密码:$userpwd"; 284 285 echo "邮箱:$useremail"; 286 287 echo ""; 288 289 echo "
"; 290 291 292 293 //mysqli_free_result($result);清除内存中的查询集 294 295 } 296 297 echo "再次处理后行数为:"; 298 299 echo mysql_num_rows($result); 300 301 mysql_free_result($result); 302 303 304 305 }
306    }
307   }

第一次写博客,希望大家多批评指正,另求php操作数据库的优秀框架php mysql_query php查询数据集的几种方式(mysql_unbuffered_query()与mysql_query()的区别),我刚从.net转为php很多不懂的,希望能得到更多的信息

公告:
1. 本站所有资源来源于用户上传和网络,如有侵权请联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系站长处理!
6. 本站不售卖代码,资源标价只是站长收集整理的辛苦费!如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。
7. 站长QQ号码 2205675299

资源库 - 资源分享下载网 » php mysql_query php查询数据集的几种方式(mysql_unbuffered_query()与mysql_query()的区别)

常见问题FAQ

关于资源售价和售后服务的说明?
本站所有资源的标价均为本站收集资源的辛苦费,不代表资源本身的价值。软件是高智慧高价值的商品,不可能是白菜价。本站资源标价只是赞助费用,收取的赞助费仅用来维持本站的日常运营!毕竟收集整理资料需要投入云计算资源和站长大量的精力。
代码有没有售后服务和技术支持?
由于代码的运行具有不可预见性,本站不保证代码完整可运行,不提供技术支持和售后服务。 本站原创代码都是站长自己开发的,可以有偿提供技术支持服务。 网站里标明【亲测】的代码都是站长亲测过的,其他的代码由于精力有限,没有一一测试,不能保证代码就一定能够使用,更没有技术支持服务,下载前请自行斟酌。
有没有搭建服务?
由于搭建服务比较费时费力,所以本站除了原创代码外均不提供搭建服务。本站分享代码纯属兴趣爱好,不以盈利为目的,请勿咨询有没有搭建服务,谢谢理解。
链接地址失效了怎么办?
请带上资源链接地址联系客服,工作时间内我们看到后将第一时间回复。
关于解压密码
本站资源一般都没有加密,如果发现需要解压密码的,那么就输入 hao.35dc.com 试试。

发表评论

资源库,由老程序员细心甄别、精心筛选,只为提供优质的源码资源

关于我们 联系我们