使用php将撇号插入SQL服务器

时间:2014-07-22 15:59:18

标签: php sql sql-server

我正在使用SQL Sever并希望在我的数据库中插入像撇号这样的特殊字符。如图所示。每当我试图插入撇号时,它都会给我一个错误。 (即使我输入双撇号''\')。任何帮助将不胜感激。

<?php   
    $connInfo = array(
        'Database' => 'databasename',
        'UID' => 'user',
        'PWD' => 'password',
        'ReturnDatesAsStrings' => true 
        );

    $connectString = sqlsrv_connect('sever.name.com', $connInfo) or die("Can't connect to the database.");

    echo "<form action=\"\" method=\"POST\">Description info:<input id=\"Description\"  type=\"text\" name=\"Description\" \" >
    <input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";

    $Description = $_POST['Description'];   
    mysql_real_escape_string($Description);//even if I remove this part and write code to replace the text with double apostrophe, it wouldn't work
    echo "<br>Description is:".$Description."<br><br>";

    $query_update = "UPDATE ElectronicShop SET Description=NULLIF('$Description','') WHERE WorkOrder=5";
    $data = sqlsrv_query($connectString, $query_update) or die(print_r(sqlsrv_errors(SQLSRV_ERR_ALL), true));       
?>

enter image description here

0 个答案:

没有答案