预处理查询函数
<?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;
时间: 2024-11-06 13:36:53