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

预处理查询函数
  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;





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