[freetds] PHP: Inserts with Unicode

Daniel Fazekas fdsubs at axelero.hu
Wed Jan 21 14:23:26 EST 2004


On Jan 21, 2004, at 9:25, Marco Brinkmann wrote:

> I can read and display all NTEXT and NVARCHAR-Fields from MSSQL 
> correctly.
> But if I try to write the read data into the database I get always the 
> parse
> error "Unclosed quotation mark...".
> The Insert looks like...
>
> db("INSERT INTO table (test) (N'".addslashes($read)."')");

1. It's asking for serious trouble if you really are using the keyword 
"table" as the name of your table. If you insist, you'll have to 
enclose it in square brackets:

INSERT INTO [table] (test) VALUES ('xxxx');

2. What's addslashes() supposed to do? MSSQL does not use slashes to 
escape quotation marks, it's the same as in Sybase, you just have to 
double any single quotation marks. For example: str_replace("'", "''", 
$str);

3. Your query seems to be missing the keyword "VALUES". It's no wonder 
if it doesn't work that way. :)

4. Try removing that N character. It should work both with and without 
it.

--
fds




More information about the FreeTDS mailing list