Hi
I have a problem trying to get the following code to work:
$user_access="1,2,3,4,5,6,7,8";
$query=$dbh->prepare("select * from table where id in (?)");
$query->execute(array($user_access));
The query gets prepared, yet nothing happens, no records are found (database is filled and entries exist) and I am faced with a syntax error. The error being "wrong datatype for integer". 😕
Apparently the values get passed to the database as strings which is of course wrong, as I am looking for simple integer values. PDO seems to try to escape the values as strings before passing them along. :queasy:
What would be the correct way of passing such a construct to the database?
I probaly could construct the SQL statement as a whole beforehand and hand it over like so:
$user_access="1,2,3,4,5,6,7,8";
$sql="select * from table where id in (".$user_access.")";
$query=$dbh->prepare($sql);
$query->execute();
But that bypasses the whole idea of PDO and I could just forget it completely and do it the old way using XX_query() directly...