I\'m looking for the alternative of mysql_real_escape_string()
for SQL Server. Is addslashes()
my best option or there is another alternative funct
After struggling with this for hours, I've come up with a solution that feels almost the best.
Chaos' answer of converting values to hexstring doesn't work with every datatype, specifically with datetime columns.
I use PHP's PDO::quote()
, but as it comes with PHP, PDO::quote()
is not supported for MS SQL Server and returns FALSE
. The solution for it to work was to download some Microsoft bundles:
After that you can connect in PHP with PDO using a DSN like the following example:
sqlsrv:Server=192.168.0.25; Database=My_Database;
Using the UID
and PWD
parameters in the DSN didn't worked, so username and password are passed as the second and third parameters on the PDO constructor when creating the connection.
Now you can use PHP's PDO::quote()
. Enjoy.