Cine Posted February 26, 2011 Share Posted February 26, 2011 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 More sharing options...
Altrozero Posted February 26, 2011 Share Posted February 26, 2011 Try updating your version of PHP? I believe there is a current bug open on this error. http://bugs.php.net/bug.php?id=31037 Link to comment https://forums.phpfreaks.com/topic/228943-bind-param-errors/#findComment-1180084 Share on other sites More sharing options...
Cine Posted February 26, 2011 Author Share Posted February 26, 2011 Try updating your version of PHP? I believe there is a current bug open on this error. http://bugs.php.net/bug.php?id=31037 That bug is from 2004 I'm currently running php 5. Link to comment https://forums.phpfreaks.com/topic/228943-bind-param-errors/#findComment-1180086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.