Wordpress MySQL Syntax Error - mysql

Hi I'm having this MySQL error:
WordPress database error:
[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 ')' at line 1]
SELECT file_name FROM art_uploaded_files WHERE file_number in()
here's the php line:
$file_name=$wpdb->get_results("SELECT file_name FROM art_uploaded_files WHERE file_number in(".substr($_files_id,0,-1).")");
I'm using this for php upload file.

The error is happening because $_file_id is empty.
So your query resulted to this:
SELECT file_name FROM art_uploaded_files WHERE file_number in()
Pay attention to the error message.
to work your query is supposed to look like this:
SELECT file_name FROM art_uploaded_files WHERE file_number in(1,2,3,4);

Related

I can't read a database on mysql because of wrong syntax in the database name, but the database reads on other platforms like DBmaria

Hi please I am new to mysql and I'd love to know how to access a database with the name 'c-factory'. It seems mysql does not read it because of the '-' sign. I've been able to load it on dbmaria but I don't seem to be able to do it with mysql
SELECT * FROM c-factory
Error Code: 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 '-factory' at line 4 0.000 sec```

Can't find out what's wrong with this MySQL event syntax

I'm trying to create a MySQL event, and this is the syntax I'm using:
CREATE EVENT test
ON SCHEDULE AT FROM_UNIXTIME(1428005286)
DO
BEGIN
UPDATE blog_posts SET status = 'published' WHERE id = 5;
END
When I run it on Node.js (with the mySQL adapter, under Sails.js), I get no error, but the event doesn't get created. When I run it directly through phpMyAdmin, I get:
#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 '' at line 5
I have also tried adding a semicolon to END, making it END;, and removing all semicolons, and it returns a slightly similar error:
#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 'END' at line 6
I have no idea why this is happening. Any help is appreciated. Thanks.
You probably need to start with: create DEFINER=root#localhost ...
Also, since this is a one-liner, you don't need BEGIN..END

MySQL error messages do not provides useful hints, what about others?

When you have some syntactical error in a query you will be a error message like:
SQL Error (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 'foo' at line 1 */
Such error message does not provide useful hint to resolve error, e.g. what it expects at that line.
Is there any config to improve the MySQL error reporting?
What about other RDBMS (PostgreSQL, Oracle, MS SQL Server)?
Do they generate better error messages?
PostgreSQL's error messages are generally quite useful.
craig=> SELECT abc FROM no_such_table HAVING blah WHERE nonense GARBAGE;
ERROR: syntax error at or near "WHERE"
LINE 1: SELECT abc FROM no_such_table HAVING blah WHERE nonense GARB...
^
It doesn't say Syntax error near WHERE; HINT: WHERE clause may not appear after HAVING... which would be nice, but turns out to be a bit tricky to do with the parser. Nonetheless, it tells you where the error is.
It can often be more specific than this, too, it depends on the nature of the error.
Using SQL fiddle I executed following query on some RDBMS.
select foo from
Only Oracle 11g returned a smart error message:
ORA-00903: invalid table name : select foo from
Other error messages:
# SQL Server 2008
Incorrect syntax near 'from'.: select foo from
#SQLite
could not prepare statement (1 near "from": syntax error)
#PostgreSQL 9.3
ERROR: syntax error at end of input: select foo from
#MySQL 5.5
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 '' at line 1: select foo from

PHPMyadmin backslash on query

I cannot run sql queries to phpMyAdmin because every time I try to run a query (Update or Insert ) backslashes are added before quotes or double .
Example:
update bareme set code_fam='loa' WHERE code=159
I get the following error message:
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unknown Punctuation String # 31
STR: =\
SQL: updatebaremesetcode_fam=\'loa\' WHEREcode=159
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 '\'loa\' WHERE code=159' at line 1
magic_quotes_gpc=on;
magic_quotes_runtime=off;
magic_quotes_sybase=off;

Syntax error in MySQL WITH ROLLUP query in MySQL Workbench?

Any idea why the following query syntax is wrong:
SELECT year, sum(profit)
FROM BASEDATA b
group by year WITH rollup
Error Code: 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.....
MYSQL Version 5.0.77-community-log
It appears to be a bug in MySQL Workbench...the query runs fine under MySQL Query Browser.
Same error, but i found a discussion :
mysql WITH ROLLUP
if execute the query with ctrl+enter you get error, but if you execute with ctrl+alt+enter
then the query is ok!
Hope the fix this bug...