Skip to content Skip to sidebar Skip to footer

Mysql Quotes, Double Quotes Mess

I'm trying to insert content into a MySQL and it looks like that: table name is foo and the columns are: id INTEGER, name VARCHAR(50), content VARCHAR(255), url

Solution 1:

You can escape quotes with backslash:

insertinto foo (id,name,content,url) values (0, 'test123', '<div id=\'test\'>ת"\א היא עיר מצוינת</div>', 'http://www.cnn.com')

You can also use the opposite kind of quotes:

insertinto foo (id,name,content,url) values (0, 'test123', "someContent's", 'http://www.cnn.com')

Here's how to do it with WebSQL parameterized queries:

transaction.executeSQL('INSERT INTO foo (id, name, content, url) VALUES (?, ?, ?, ?)',
    [0, 'test123', '<div id=\'test\'>ת"\א היא עיר מצוינת</div>', 'http://www.cnn.com'],
    callbackfn);

Solution 2:

You escape any string only for what's around it. So if you want to put double quotes around this one, you have to protect only the double quote inside.

Solution 3:

You can escape a quote using \ also known as the escape character. Have a look at this page that showcases the available escape sequences.

Solution 4:

try this :

insertinto foo (id,name,content,url) values (0,'test123','someContent\'s','http:\/\/www.cnn.com')

Post a Comment for "Mysql Quotes, Double Quotes Mess"