The message doesn’t tell you what’s wrong, only where the parser gave up. On MariaDB it reads almost the same but mentions MariaDB server version. A full example:
ERROR 1064 (42000): 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 FROM sales WHERE order > 10' at line 1
The quoted text after near starts at order, which is a reserved word in SQL. That’s the problem.
Causes
- A reserved word used as a column or table name without backticks:
order,group,key,desc, andrankin MySQL 8. - A missing or extra comma, bracket or quote.
- Curly quotes pasted from Word or a web page (‘ ’ “ ”) instead of plain ’ and “.
- An apostrophe in the data of a query built by string concatenation in PHP, such as
O'Neil, which is also an SQL injection hole. - An empty variable in the query, like
WHERE id =with no value, which givesnear '' at line 1. - A dump from another system, such as PostgreSQL, or syntax specific to a different version.
- Stored procedures or triggers run in phpMyAdmin without changing the delimiter.
How to fix it
- Read the near part and look just before it. In the example above, wrap the column in backticks:
SELECT id, `order` FROM sales WHERE `order` > 10;
- Print the final query exactly as MySQL receives it. In plain PHP, echo the variable before running it; in Laravel:
DB::enableQueryLog();
// ... code that runs the query
dd(DB::getQueryLog());
Then paste it into the SQL tab of phpMyAdmin to see the exact error.
- Use prepared statements instead of concatenation:
$stmt = $pdo->prepare('SELECT * FROM users WHERE name = ?');
$stmt->execute([$name]);
The apostrophe in O'Neil no longer breaks anything, and nobody can inject SQL.
-
Replace pasted quotes with plain keyboard quotes, and write queries in a code editor, not a word processor.
-
When importing a file, phpMyAdmin shows the statement that failed. If the dump comes from another system such as PostgreSQL, convert it first or re-export it from the source in MySQL format.
-
When creating a stored procedure in the SQL tab, change the Delimiter field below the query box to
$$and write:
CREATE PROCEDURE count_orders()
BEGIN
SELECT COUNT(*) FROM orders;
END $$
Prevention
- Use an ORM or query builder such as Eloquent, which quotes identifiers and values for you.
- Avoid reserved words when naming columns and tables:
order_number, notorder. - Try new queries in phpMyAdmin before putting them in code.
On ArabyHost
Databases run on MariaDB/MySQL with phpMyAdmin, so the message may say MariaDB instead of MySQL; the fix is the same. Paste the query into phpMyAdmin’s SQL tab to see which line fails. If the error shows up in your site’s log and you can’t tell which query caused it, ask the Araby AI assistant in the panel: it reads the error log and explains which part is wrong and how to correct it. For custom PHP projects, see the developers page.
FAQ
How do I find where the error is?
Look at the text after near: that's where the parser stopped, and the mistake is usually right before it. The line number at the end refers to the line inside the query.
Why do names with an apostrophe, like O'Neil, break my query?
The query is built by concatenating strings, so the apostrophe ends the string early. Use prepared statements: they fix this and protect you from SQL injection.
What does near '' at line 1 mean?
The query ended before it was complete: an unclosed bracket or quote, or an empty variable at the end. Print the final query to see what actually reached MySQL.