预处理查询函数![](https://images0.cnblogs.com/blog/736985/201506/050045255195136.png)
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$dbname = 'db';
$charset = 'utf8';
$m = new mysqli($host,$user,$pass,$dbname);
$m->set_charset($charset);
//$tn为表名,$w为条件
function get_count($tn,$w='1=1'){
global $m;
$stmt=$m->prepare("select count(*) from $tn where $w");
$stmt->execute();
$stmt->bind_result($c);
$stmt->fetch();
$stmt->free_result();
$stmt->close();
return $c;
}
查询函数的使用
$re=get_count('stu','sscore=90');
echo $re;
![](https://images0.cnblogs.com/blog/736985/201506/050045255195136.png)