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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.