PHP PDO SQL Server Select statement not replacing question marks
- by Metropolis
Awhile ago I wrote a database class which uses PDO in order to connect to SQL Server databases and also to MySQL databases. It has always replaced the question marks fine when using it on the MySQL databases, but for the SQL Server database I had to create a work around which basically replaces the question marks manually. Here is the code for that.
if($this->getPDODriver() == 'odbc' && !empty($values_a) && substr_count($query_s, "?") > 0) {
$query_s = preg_replace(array_fill(0, substr_count($query_s, "?"), '/\?/'), $values_a, $query_s, 1);
$values_a = NULL;
}
Now, I understand that this completely defeats the purpose of the question marks and PDO, but it has been working fine for me. What I would like to do now though, is find out why the question marks are not getting replaced in the first place, and remove this workaround.
If I have a select statement like the following
SELECT * FROM database WHERE value = ?
That is what the query looks like when I go to prepare it, but when I display the query results, it is a blank array.
Just remember, this class is working fine with MySQL, and it is working fine with the work around above. So I know it has something to do with the question marks.