我正在为mysql查询开发类
主要目的是运行任何查询(选择,插入,更新),如果它选择它应该返回结果数据,如果它是updata或insert,它应该返回受影响的行数。
但以下代码抛出错误错误就在这一行 if($ stmt-> bind_param($ types,$ escaped))
<?php
class sqli{
public $mysqli;
public function __construct($host, $username, $password, $dbname){
$this->mysqli = new mysqli($host, $username, $password, $dbname);
if($this->mysqli->connect_errno){
echo $this->mysqli->connect_error;
die("could not connect to mysql database");
}
}
public function query($qry,$types,$array){
if(!empty($qry)){
if($stmt = $this->mysqli->prepare($qry)){
if(count($array)>0 &&!empty($array)){
$escaped = array();
foreach($array as $value){
$value= $this->mysqli->real_escape_string($value);
$escaped[]=$value;
}
$escaped = join("','",$escaped);
$escaped = "'".$escaped."'";
echo count($types);
echo $escaped;
echo count($escaped);
if(!empty($types)){
if($stmt->bind_param($types, $escaped)){
if($stmt->execute()){
if($prefetch = $stmt->get_result()){
$result = array();
while($row=$prefetch->fetch_array()){
$result[]=$row;
}
return $result;
}elseif($stmt->affected_rows){
return $stmt->affected_rows;
}
}
}
}
}else{
if($stmt->execute()){
if($prefetch = $stmt->get_result()){
$result = array();
while($row=$prefetch->fetch_array()){
$result[]=$row;
}
return $result;
}elseif($stmt->affected_rows){
return $stmt->affected_rows;
}
}
}
}
}else{
return false;
}
}
}
$mysqli = new sqli($params['db_host'],$params['db_user'],$params['db_pass'],$params['db_name']);
$qry = "select * from tbl_chat where from_id=? and to_id=?";
$result = $mysqli->query($qry,'ii',array('717','1543'));
如果我从tbl_chat运行查询,例如select *,它可以正常工作
请帮忙