码迷,mamicode.com
首页 > 其他好文 > 详细

预处理语句获得总记录数的函数及其调用

时间:2015-06-05 06:10:31      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

预处理查询函数
  1. <?php
  2. $host = ‘localhost‘;
  3. $user = ‘root‘;
  4. $pass = ‘‘;
  5. $dbname = ‘db‘;
  6. $charset = ‘utf8‘;
  7. $m = new mysqli($host,$user,$pass,$dbname);
  8. $m->set_charset($charset);
  9. //$tn为表名,$w为条件
  10. function get_count($tn,$w=‘1=1‘){
  11. global $m;
  12. $stmt=$m->prepare("select count(*) from $tn where $w");
  13. $stmt->execute();
  14. $stmt->bind_result($c);
  15. $stmt->fetch();
  16. $stmt->free_result();
  17. $stmt->close();
  18. return $c;
  19. }
查询函数的使用
  1. $re=get_count(‘stu‘,‘sscore=90‘);
  2. echo $re;
技术分享




预处理语句获得总记录数的函数及其调用

标签:

原文地址:http://www.cnblogs.com/lsr111/p/4553520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!