I am working on an application using PHP object oriented with PDO. I have been struggling for hours finding the problem of why my query execution failed. It turned out that I have supplied a value as parameter in String format to be binded in an array. I have a general loop that binds all of the parameters to the question mark placeholder for my query. That of course will consider the parameters are all in String format. However I have columns in integer format. Even when I cast the variable to integer using (int)
or intval()
, it did not work. So I believe I have to specify the explicit data type to PDO::PDO_PARAM_INT
. But I have code something like this for all queries:
Example of query:
$this->db->query("INSERT INTO users (name, numberOfCar") VALUES (?,?) ,
array('Jake', 5));
The bindValue() part:
$x = 1;
if( count($params) ){
foreach($params as $param){
$this->_query->bindValue($x, $param);
$x++;
}
}
How do I go with this? I mean any idea how can I modify the code to catter this issue? Not sure whether I have to modify which part of code but I am puzzled to think the workaround of this. Thank you in advance.
EDIT: PHP version 5.3.10, PDO connect to Sybase