
The 1064 is the database saying it did not understand the SQL statement: it is written in a way the database does not accept. The message always ends with a note like ... right syntax to use near 'FROM orders' at line 3. The golden rule is this: the fault is immediately before the quoted piece, not in it.
The causes that keep coming back
| What you see | The cause and the cure |
| A column called order, group, key or desc | They are reserved SQL words. Put the name between backticks: `order`. Or rename the column. |
| Text containing an apostrophe (O’Brien) | The apostrophe closes the text string halfway. The cure is not to “escape” by hand: it is to use prepared statements (parameters), which also close the door on SQL injection. |
| A stray comma before FROM or at the end of the list | A comma after the last field. Count them. |
| An empty variable: WHERE id = with no value | The code built the query with an empty variable. Write the query to the log before running it and see what was really sent. |
| It fails on import, at line 12874 | The number is the line of the file. Open it in an editor and go to that line: very often the file is cut halfway (an interrupted upload). |
| Works on another server, not here | Syntax from a different version. Here the engine is MariaDB, not Oracle’s MySQL. See MySQL or MariaDB: which one runs here. |
Finding the line, step by step
|
|
|
|
|
| Do not build queries by pasting in text from forms. Besides the 1064 that an apostrophe brings, that is how the door opens to SQL injection, one of the oldest and most exploited security flaws. Use parameters: a working example is in connecting to MySQL from PHP: mysqli and PDO. |
| A note on versions. Some statements exist in only one of the two engines. For example ADD COLUMN IF NOT EXISTS exists in MariaDB and not in Oracle’s MySQL. If a statement works on one machine and breaks on another, first check which engine and which version each one runs. |
|
Cannot find the line? Send us the whole message and, for an import, the line number. Open a support ticket |
|
SEE ALSO Connecting to MySQL from PHP: mysqli and PDO, with a working example MySQL or MariaDB: which one runs here, and does it matter Importing with phpMyAdmin, and the size limit that stops you |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 5.940,00 Kz/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











