php - mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables -
i developing class mysql query
main purpose run query (select, insert, update) if it's select should return result data, , if it's updata or insert should return number of rows affected.
but following code throws error error in line 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 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 $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 * tbl_chat from_id=? , to_id=?"; $result = $mysqli->query($qry,'ii',array('717','1543'));
if run query select * tbl_chat works fine
please
Comments
Post a Comment