Question

SQL requests with double-quotes not working with managed database

I have a php app that successfully makes SQL requests against MySQL servers. Nevertheless the same app breaks against DO managed database whenever the requests include double-quotes.

The following request returns an error 1054 with managed database while it works with classic MySQL servers.

select * from users where username="demo" 
=> error 1054

select * from users where username='demo'
=> ok

Is there a way to configure DO managed database to accept double-quotes?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Andrew Moore
DigitalOcean Employee
DigitalOcean Employee badge
January 26, 2020
Accepted Answer

This is related to the sql_mode used. There’s a sql_mode setting, ‘ANSI_QUOTES’ that will make the " an identifier character.

e.g.

mysql> set session sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES';
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t1 where c3="foo";  <-- double quotes operating the same as `
ERROR 1054 (42S22): Unknown column 'foo' in 'where clause'

mysql> select * from t1 where c3='foo';  <-- single quotes works
+----+----+----+------+
| id | c1 | c2 | c3   |
+----+----+----+------+
|  3 |  5 |  6 | foo  |
+----+----+----+------+
1 row in set (0.00 sec)

mysql> set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected (0.00 sec)

mysql> select * from t1 where c3="foo";
+----+----+----+------+
| id | c1 | c2 | c3   |
+----+----+----+------+
|  3 |  5 |  6 | foo  |
+----+----+----+------+
1 row in set (0.00 sec)

I’ve removed the ANSI_QUOTES sql-mode setting at a session level.

You can change the global value under the settings tab of your instance(s).

Hope this solves your issue!

Andrew

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel