$tn为表明,$f为查询的字段名,不写则为全部,$w为条件,$o为按照顺序排序,$l为显示几条信息
预处理查询函数
<?php
$host = ‘localhost‘;
$user = ‘root‘;
$pass = ‘‘;
$dbname = ‘db‘;
$charset = ‘utf8‘;
$m = new mysqli($host,$user,$pass,$dbname);
$m->set_charset($charset);
//$tn为表明,$f为查询的字段名,不写则为全部,$w为条件,$o为按照顺序排序,$l为显示几条信息
function select($tn,$f=‘*‘,$w=‘1=1‘,$o=‘‘,$l=0){
global $m;
if($l<=0){
$stmt=$m->prepare("select $f from $tn where $w $o");
}else{
$stmt=$m->prepare("select $f from $tn where $w $o limit $l");
}
$stmt->execute();
$rows=$stmt->get_result()->fetch_all(2);
$stmt->free_result();
$stmt->close();
return $rows;
}
预处理查询函数的使用
//查询语句函数的使用$tn为表明,$f为查询的字段名,不写则为全部,$w为条件,$o为按照顺序排序,$l为显示几条信息
$re=select(‘stu‘,‘sname,sscore‘,‘sscore>10‘,‘order by sscore asc‘,5 );
echo ‘<pre>‘;
var_dump($re);
时间: 2024-12-14 20:17:04