查询:
$mysql = new mysqli('localhost','root','root','ganbaobao_ucenter');
/*
普通方法:
$query = $mysql->query("select username,email from uc_members where uid < 100000");
$result = array();
while($result = $query->fetch_array())
{
$result[] = array('name'=>$result['username'],'email'=>$result['email']);
}
*/
$query_prepare = $mysql->prepare("select username,email from uc_members where uid < ?");
$id = 100000;
$query_prepare->bind_param("i",$id);
$query_prepare->execute();
$query_prepare->bind_result($username,$email); //查找两个值
$result = array();
while($query_prepare->fetch())
{
$result[] = array('name'=>$username,'email'=>$email);
}
或者:
$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?');
$stmt->bind_param('s', $name);//绑定数据
$stmt->execute();///执行数据
$result = $stmt->get_result();//获取所有数据
while ($row = $result->fetch_assoc()) {
// do something with $row
}
更新: