开发者

Unclosed quotation mark after the character string ''

Trying to insert a lot of records from a MySQL database into SQL Server(2005 SQLExpress) database. Here's the quer开发者_开发问答y and the error from PHP. I am not understanding it. All opening strings are closed properly but still..

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

What could be the problem. I ran this query singly through SQL Server management console and it accepted and inserted. I even ran this query in another PHP file and data was inserted. However, when I do it in a PHP loop then this problem., The code snippet is,

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

Edit:

I used PDO now and here's what the errorInfo returns.

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


The old mssql extension is outdated. Switch to the SQL Server PHP driver (the PDO version), so you can use prepared statements, which are safer, more performant and won't suffer from any value coding issues, since values are kept separate from the rest of the statement.

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


try stripping out all but essential NOT NULL column names and associated values, and then add them back in slowly.

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

Question: is "function.mssql-query" a PHP function?

It would be nice to see what SQL Server is receiving. Perhaps enable some client side logging. Your SQL looks visually okay to me.

Probably if you include the create table statement, that'll allow people to help a bit more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜