字符串''后面的未闭合引号

时间:2011-05-31 09:23:00

标签: php mysql sql-server

尝试将MySQL数据库中的大量记录插入SQL Server(2005 SQLExpress)数据库。这是来自PHP的查询和错误。我不理解。所有打开的字符串都正确关闭但仍然是..

INSERT INTO tbl_email (uniq_id, Respondent_ID, Bcode, BID, Email, Voornaam, Voorletters, Tussenvoegsel, Achternaam, Geslacht, Adres, Huisnummer, Toevoeging, Postcodecijfers, Postcodeletters, Woonplaats, Land, Telefoon1, Mobiel, Telefoon2, Matchkey, Profile, Geboortejaar, Geboortedatum, Leefsituatie, Gezinsgrootte, Inkomen, Beroep, Opleiding, Huis, Huisjaar, Huistype, Tuin, Auto, Beleggen, Kopenopafstand, Financien, Respondenttype, Charitype, Chari, Postcode, Huisdier, EV2, EV3, EV4, EV5, EV6, EV7, EV8, EV9, Aanmaakdatum, fk_ID_projectreactie, status_subscribed, unsubscribeddate, insertdatetime, editdatetime, to_delete) VALUES (6, "41", "288", "53", "test@hotmail.com", "a", "M", "", "0", "2", "0", "176", "", "5652", "EP", "a", "", "", "0", "0", "0", "", "0", "", "2", "2", "", "4", "4", "1", "2006", "", "", "", "1", "1", "", "3", "", "", "a", "1", "", "", "", "", "", "", "", "", "a", 0, 0, Null, Null, Null, 1)
Warning: mssql_query() [function.mssql-query]: message: Unclosed quotation mark after the character string ''. (severity 15) in crn_export_mssql.php on line 94

可能是什么问题。我通过SQL Server管理控制台单独运行此查询,并接受并插入。我甚至在另一个PHP文件中运行此查询并插入了数据。但是,当我在PHP循环中执行此问题时,代码片段为

while(//get rows from mysql)
{ //create query on runtime
$query = $strInsertDump . '('.implode(', ', $arrInsertField).')';
$result = mssql_query($query, $mslink);
}

编辑:

我现在使用PDO,这是errorInfo返回的内容。

Array
(
[0] => HY000
[1] => 20018
[2] => Incorrect syntax near ''. [20018] (severity 5) [(null)]
[3] => -1
[4] => 5
[5] => OpenClient
)

2 个答案:

答案 0 :(得分:2)

旧的mssql扩展已过时。切换到SQL Server PHP driverPDO版本),这样您就可以使用prepared statements,它更安全,性能更高,不会受到任何价值编码问题的困扰,因为价值是分开的从声明的其余部分开始。

$query = $db->prepare('INSERT INTO tbl_email (uniq_id, Respondent_ID, Bcode, ...) 
                       VALUES (:uid, :rid, :bcode, ...)');
while (/* ... */) {
    $query->execute(array(':uid' => ..., ':rid' => ..., ':bcode' => ..., ...));
}

答案 1 :(得分:0)

尝试剥离所有但必不可少的NOT NULL列名和关联值,然后慢慢添加它们。

INSERT INTO tbl_email (uniq_id, Respondent_ID)
) VALUES (6, "41")

问题:“function.mssql-query”是一个PHP函数吗?

很高兴看到SQL Server正在接收什么。也许启用一些客户端日志记录。您的SQL看起来对我来说没问题。

如果你包含create table语句,可能会让人们多一点帮助。