I am attempting to properly bind parameters to a statement with the Function below. I am passing in an associative array, value=>datatype.
I am getting an error though while attempting this: Notice: Undefined offset: 0 in db.class.php on line 69 Notice: Undefined offset: 1 in db.class.php on line 69
Line 69 is the for line in Function
How do I fix this? And/Or should I even bother doing it like this?
Here's Function
protected function ConvertParams($stmt, $params){ $parrs = $params; if(is_array($parrs)){ $parrCt = count($parrs); echo '<pre>'; print_r($parrs); echo '</pre>'; echo '<hr />'; for($i = 0; $i < $parrCt; ++$i){ switch ($parrs[$i][1]){ case 'string': $stmt->bindParam($i + 1, $parrs[$i][0], PDO::PARAM_STR); break; case 'int': $stmt->bindParam($i + 1, $parrs[$i][0], PDO::PARAM_INT); break; case 'boolean': $stmt->bindParam($i + 1, $parrs[$i][0], PDO::PARAM_BOOL); break; case 'lob': $stmt->bindParam($i + 1, $parrs[$i][0], PDO::PARAM_LOB); break; default: $stmt->bindParam($i + 1, $parrs[$i][0]); } } } } Here's the array:
$db->Params = array('%a%'=>'string', '%Welcome%'=>'string'); Please assume that I am connecting to the db correctly, and that the query properly executes (minus this bindParam issue).