I created a function to print a prepared-statement-sql-string with the variables in it, based on what I found in this other StackOverflow question.
Here is my code:
foreach($params as $idx => $param) {
if ($idx == 0) continue;
$sql = str_replace('?', "'" . $param . "'", $sql, 1);
}
printError($sql);
When I run this I get: Fatal error: Only variables can be passed by reference
for line 3. However when i use
$sql = preg_replace('/\?/', "'" . $param . "'", $sql, 1);
for line 3 it works fine.
Any idea why?