How to escape strings in SQL Server using PHP?

前端 未结 14 1479
我寻月下人不归
我寻月下人不归 2020-11-22 09:36

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

相关标签:
14条回答
  • 2020-11-22 10:07

    You could look into the PDO Library. You can use prepared statements with PDO, which will automatically escape any bad characters in your strings if you do the prepared statements correctly. This is for PHP 5 only I think.

    0 讨论(0)
  • 2020-11-22 10:07

    Warning: This function was REMOVED in PHP 7.0.0.

    http://php.net/manual/en/function.mssql-query.php

    For anyone still using these mssql_* functions, keep in mind that they have been removed from PHP as of v7.0.0. So, that means you eventually have to rewrite your model code to either use the PDO library, sqlsrv_* etc. If you're looking for something with a "quoting/escaping" method, I would recommend PDO.

    Alternatives to this function include: PDO::query(), sqlsrv_query() and odbc_exec()

    0 讨论(0)
提交回复
热议问题