How to escape strings in SQL Server using PHP?

前端 未结 14 1511
我寻月下人不归
我寻月下人不归 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 09:55

    In order to escape single- and double-quotes, you have to double them up:

    $value = 'This is a quote, "I said, 'Hi'"';
    
    $value = str_replace( "'", "''", $value ); 
    

    $value = str_replace( '"', '""', $value );

    $query = "INSERT INTO TableName ( TextFieldName ) VALUES ( '$value' ) ";
    

    etc...

    and attribution: Escape Character In Microsoft SQL Server 2000

提交回复
热议问题