首页 > 其他 > 详细

预处理语句查询函数

时间:2015-06-05 06:12:01      阅读:216      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!