We are using MSSQL in combination with Laravel which uses the dblib PDO library from PHP. I've looked in the illuminate database part and see that it uses the PDO->prepare($query)->execute($bindings). So I am expecting that it would execute a prepared statement at the SQL database.
But when I check the table to analyse the queries that were run. I see that the queries didn't run as a prepared statement but instead the queries were classified as an Adhoc query.
Do any of you guys know why PHP/Laravel/FreeTDS/MSSQL is behaving like this or have any ideas on how to fix it?
Thanks!
I think prepared statements via
freetds->pdo_dblibare unsupported. I do not, however, have proof of this and apologise for making an 'answer' that is non-definitive. My hope is that this pushes the issue further along / provides some surface area for those with more knowledge.Is it expected this functionality is supported? I would say yes.
As per that above thread,
freetds 4.2states:However, the omission of that from later versions would imply it is supported (we are using
freetds 7.3).How am I determining this isn't working?
Unrelated to Laravel (although still PHP - 7.1) I am unable to get prepared statements working using the
pdo_dblibdriver.The query I'm using to ascertain prepared statements are actually being used:
I've tried a very simple query taking 2 int parameters, with the PHP code looking like:
Is there a workaround?
Using the /exact/ same PHP code and changing the underlying driver to
pdo_sqlsrv, I can begin to see theusecountsincrease, whereas withpdo_dblibI do not see that.The above SO thread had a 'solution' of swapping to the
ODBCdriver (although not clarifying why this isn't working withdblib).What is the actual cause?
So, it is still unclear to me why this functionality doesn't seem to be working. The only other information I can find about this is from a buried php.net bug from 2017:
https://bugs.php.net/bug.php?id=74592