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

预处理语句查询函数

时间:2015-06-05 06:14:35      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

$tn为表明,$f为查询的字段名,不写则为全部,$w为条件,$o为按照顺序排序,$l为显示几条信息
预处理查询函数
  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为表明,$f为查询的字段名,不写则为全部,$w为条件,$o为按照顺序排序,$l为显示几条信息
  10. function select($tn,$f=‘*‘,$w=‘1=1‘,$o=‘‘,$l=0){
  11. global $m;
  12. if($l<=0){
  13. $stmt=$m->prepare("select $f from $tn where $w $o");
  14. }else{
  15. $stmt=$m->prepare("select $f from $tn where $w $o limit $l");
  16. }
  17. $stmt->execute();
  18. $rows=$stmt->get_result()->fetch_all(2);
  19. $stmt->free_result();
  20. $stmt->close();
  21. return $rows;
  22. }
预处理查询函数的使用
  1. //查询语句函数的使用$tn为表明,$f为查询的字段名,不写则为全部,$w为条件,$o为按照顺序排序,$l为显示几条信息
  2. $re=select(‘stu‘,‘sname,sscore‘,‘sscore>10‘,‘order by sscore asc‘,5 );
  3. echo ‘<pre>‘;
  4. var_dump($re);






预处理语句查询函数

标签:

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

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