CodeIgniter Forums
Database Backup with Reserved Keyword - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Database Backup with Reserved Keyword (/thread-33002.html)



Database Backup with Reserved Keyword - El Forum - 08-11-2010

[eluser]TigerWolf[/eluser]
The Bug

I found this error when trying to backup my database:

Code:
A Database Error Occurred

Error Number: 1064

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 'order' at line 1

SELECT * FROM order

This is because one of my table names ("Order") is a mysql reserved word. This broke the database backup. If I deleted this table the problem went away.

I went digging in the code and found where the problem was:

The Fix

If you check out line 132 of mysql_utility in system/database/drivers/mysql - This line appears:

Code:
$query = $this->db->query("SELECT * FROM $table");
Changing it to

Code:
$query = $this->db->query("SELECT * FROM `$table`");

Fixes the problem mentioned above.

Thanks.

So what should I do next?