Jump to content

Bind Param Errors


Cine

Recommended Posts

Hello,

 

I'm getting some errors when binding parameters inside a loop, and it's doing my head in :)


public function query($sql, $params) {
       
	if(!$sobj = $this->conn->prepare($sql)) {
               
		die('Query Prepare Error (' . $this->conn->mysqli_errno . ') '
			. $this->conn->mysqli_error);
               
	} else {
               
		if(!is_array($params)) {
                       
			$params = array_slice(func_get_args(), 1);

		}

		foreach($params as $value) {
                       
			$type = strtolower(gettype($value));
			$sobj->bind_param($type[0], $this->conn->real_escape_string($value));
                       
		}                      
               
		$sobj->execute();
		$sobj->bind_result($result);
		$sobj->fetch();
               
		$sobj->close();

		return $result;
               
	}

}


 

The errors I'm getting is:

 

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in /nfs/c06/h02/mnt/97387/domains/nickythorne.com/html/v2/includes/classes/class_db2.php on line 67

Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in /nfs/c06/h02/mnt/97387/domains/nickythorne.com/html/v2/includes/classes/class_db2.php on line 67

 

(Line 67 is $sobj->bind_param($type[0], $this->conn->real_escape_string($value)); above)

 

I'm calling the function like this:

$details = new DB();
echo $details->query("SELECT `postcode` FROM `details` WHERE `name` = ?  and `address` = ?", array("Josh", "45 Ashdale Road"));

 

 

Does anyone know how I can solve this?

 

 

Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/228943-bind-param-errors/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.