0

I'm trying to insert some binary data into database using 'mysql' gem in ruby. But as the binary data contains many single and double quotes, the following code fails. Please help me to fix it.

m = mysql.prepare("insert into data (binary) values ('#{binary_data}') ")

Error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.......' at line 1 (Mysql::Error)

2 Answers 2

2

binary is reserved word in mysql so wrap it with apostrophe like

insert into data (`binary`) ......
Sign up to request clarification or add additional context in comments.

Comments

1

You're using prepared statements wrong. What about this?

stmnt = mysql.prepare("insert into data (`binary`) values (?)")
stmnt.execute binary

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.