简体   繁体   中英

Escaping special characters while inserting in mysql

I am inserting multi-rows in a mysql database by concating values as in the query

INSERT INTO tableName (col1, col2, col3) VALUES('a', 'b', 'c'), ('d', 'b', 'c'), ('e', 'b', 'c');

However, sometimes some of the values of the entire bunch needs to be escaped, like I got s-â€__83164 as one of my values to enter. This causes the entire bunch of request to drop when only one or two of the values are faulty.

Is there any way to escape characters like s-â€__83164 or do I need a modification in the type of field, I am using for it. I am currently using VARCHAR for storing those values.

Please comment if I am unclear in asking my doubt !

One thing that you can do, is get all characters into variables and then place those variables in your SQL query. While declaring the variable you can use single quotes to include your data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM