查询数据库里面有多少条数据
$m=new mysqli(‘localhost‘,‘root‘,‘‘,‘db‘);
$m->set_charset(‘utf8‘);
$stmt=$m->prepare(‘select count(*) from stu‘);
$stmt->execute();
$stmt->bind_result($c);
$stmt->fetch();
echo $c;
$stmt->free_result();
$stmt->close();
$m->close();
使用预处理语句实现数据的查询方法一:
$m=new mysqli(‘localhost‘,‘root‘,‘‘,‘db‘);
$m->set_charset(‘utf8‘);
$stmt=$m->prepare(‘select * from stu where 1=1‘);
$stmt->execute();
$stmt->bind_result($id,$name,$sgender,$sscore);
while($stmt->fetch()){
echo "$id,$name,$sgender,$sscore".‘<br>‘;
}
$stmt->free_result();
$stmt->close();
$m->close();
使用预处理语句实现数据的查询方法二:
$m=new mysqli(‘localhost‘,‘root‘,‘‘,‘db‘);
$m->set_charset(‘utf8‘);
$stmt=$m->prepare(‘select * from stu where 1=1‘);
$stmt->execute();
$result=$stmt->get_result();
$rows=$result->fetch_all(2);
foreach($rows as $v){
print_r($v).‘<br>‘;
}
$stmt->free_result();
$stmt->close();
$m->close();
使用预处理语句实现数据的查询方法三:
$m=new mysqli(‘localhost‘,‘root‘,‘‘,‘db‘);
$m->set_charset(‘utf8‘);
$stmt=$m->prepare(‘select * from stu where sid=?‘);
$n=10;
$stmt->bind_param(‘i‘,$n);
$stmt->execute();
$stmt->bind_result($id,$name,$sgender,$sscore);
$stmt->fetch();
echo $id,$name,$sgender,$sscore;
$stmt->free_result();
$stmt->close();
$m->close();
时间: 2024-10-29 19:06:22