By shonore
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?
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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.