Skip to content
Advertisement

MSSQL, PDO, error when inserting XML string: General error: 102 Incorrect syntax near ‘<?xml version="1.0"

I am trying to insert XML string into a MSSQL database from PHP. I get:

SQLSTATE[HY000]: General error: 102 Incorrect syntax near ‘ (a chunk of the xml follows).

The prepared statement is:

The $xml is a valid XML string. The same XML can be inserted OK using an identical statement in an SQL client app (sqlectron)

I have no idea what to do next.

Advertisement

Answer

The problem was caused by encoding. The XML was encoded with Windows-1250, but the database connection was opened with UTF-8 charset:

After changing UTF-8 to WINDOWS-1250 in the DSN ($connString):

the XML can be inserted with no problem.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement