I created my database tables and bake as usual with CakePHP 3 but when I point my browser to some link it give me this errors:
Error: SQLSTATE[42000]: Syntax error or access violation: 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 'AS Users__contact person, Users.Phoneno AS Users__Phoneno, Users.email AS `U' at line 1
If you are using SQL keywords as table column names, you can enable identifier quoting for your database connection in config/app.php.
SQL Query:
SELECT Users.id AS `Users__id`,
Users.name AS `Users__name`,
Users.address AS `Users__address`,
Users.contact person AS `Users__contact person`,
Users.Phoneno AS `Users__Phoneno`,
Users.email AS `Users__email`
FROM users Users
LIMIT 20 OFFSET 0
Thanks guys and #RiggsFolly nice to have observerd that in the SQL
The error was from the space in the column contact person instead of contactperson in the SQL
Related
I have a column with null values in it and one is empty. Now I am trying to fetch both but it shows me an SQL syntax error. Please guide me on how can i fetch both empty and null columns.
SQLSTATE[42000]: Syntax error or access violation: 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 ',,,,,,42450,42706,42962,43218,43474,43730,43994,44250,44506,44762,45018,45274,45' at line 1 (SQL: select token_id, email_state, email_event_time, created_at as email_created_at from email_tracker where transaction_id = 2856 and email_tracker.id IN (SELECT max(id) FROM email_tracker WHERE token_id IN (,,,,,,,42450,42706,42962,43218,43474,43730,43994,44250,44506,44762,45018,45274,45530,45793,46049,46305,46561,46817,47073,47329,47585,47841,48097,48353,48609,48880,49136,49392,49648,49904,50160,50700,50956,51212,51468,51724,51980,52236,52492,52748,53004,53260,53516) GROUP BY token_id) order by created_at desc)
$this->replies->where($field_name,'=', '')->orWhereNull($field_name);
Please guide me on what I am doing wrong here.
Any solution appreciated!
I have a following query:
"DELETE * FROM Participations WHERE scheduleId IN (SELECT id FROM Schedule WHERE meetingId = :meetingId) AND userId = :userId"
I assign variables using PDO properly.
In response I get:
SQLSTATE[42000]: Syntax error or access violation: 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 '* FROM Participations WHERE scheduleId IN (SELECT id FROM Schedule WHERE meeting' at line 1}
It is enough that I replace first DELETE with SELECT and query is done properly.
Besides when I test directly in phpMyAdmin the same query with DELETE in it works fine.
I am confused....
Use DELETE FROM (note the lack of *) instead.
The error message clearly indicates that it is a syntax error near '*'.
Remove * from your Delete statement
DELETE FROM Participations WHERE scheduleId IN
(SELECT id FROM Schedule WHERE meetingId = :meetingId) AND userId = :userId
I am relatively new to somewhat advanced MySQL querying. I had been trying to query the most recent order in an order table of a particular user using MySQL SELECT statement using the following MySQL query.
SELECT o1.* FROM order AS o1
WHERE o1.orderDateTime =
(
SELECT MAX(o2.orderDateTime) FROM order AS o2
WHERE o2.userId = '1'
)
But I had been constantly getting the following MySQL error #1064 related to MySQL syntax.
#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 AS o1 WHERE o1.orderDateTime = (SELECT MAX(o2.orderDateTime)FROM order AS ' at line 1
I got similar errors in relation with INSERT statements but I managed to fix it up using the methods specified in MySQL 1064: You have an error in your SQL syntax
I made every effort to fix the query in the current case but I was still unsuccessful.
I would be grateful to you if someone can help me out with fixing this MySQL syntax error for SELECT clause specified above. It would be great if someone could specify me the exact reason for the occurrence of this issue, as well.
order is a reserved word and its a bad choice for table name. You need to escape using backticks in the query
SELECT o1.* FROM `order` AS o1
WHERE o1.orderDateTime = (
SELECT MAX(o2.orderDateTime) FROM `order` AS o2
WHERE o2.userId = '1'
)
http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html
As per #Abhik, order is a MySQL keyword.
And you should avoid collapse with two methods:
Use backticks (`) (#Abhik has already explained this.)
Prepend Database name before Table Name e.g.
DataBase_Name.order.
But, still #Abhik's approach is preferable as in case of database name change, you need to change DataBase name in your query.
First of all you could follow #Abhik Chakraborty suggestion to include back ticks around order table name. order is a reserved word in mysql. My suggestion was to improve your sql query. YOu could acomplish the same using:
SELECT o1.* FROM `order` o1
WHERE o1.userId = '1' order by orderDateTime desc limit 1
the subquery seems unnecessary.
I have a bunch of php files corresponding to an application I am writing, using MySQL for my database structure. I know this questions has been asked before but I've been through most of the posts about it and can't find something that will help...
In my PHP file I have a SQL query
$group_sql = "INSERT INTO group (name, description, ownerEmail) VALUES ('$groupName', '$descrip', '$owner')";
that corresponds to a group table with three attributes: name, description, and owner email. $groupName, $descrip, $owner are three variables I have defined. I'm getting this syntax error when I try to run the query:
Error: INSERT INTO group(name, description, ownerEmail) VALUES(hi, hi, test#example.com)
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 'group(name, description, ownerEmail) VALUES(hi, hi, test#example.com)' at line 1
Can someone please help me see what I'm doing wrong?
GROUP is a MySQL reserved keyword. If you name a table that, then you must wrap it in ticks:
$group_sql = "INSERT INTO `group` (name, description, ownerEmail)
VALUES ('$groupName', '$descrip', '$owner')";
Notice where SQL starts with the error and points to it?
>for the right syntax to use near 'group
> ^
This applies to both tables and columns.
Consult: http://dev.mysql.com/doc/refman/5.0/en/identifier-qualifiers.html
I have the following 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 'select manufacturers_id, manufacturers_name, manufacturers_image, date_added, la' at line 1
The query:
SELECT COUNT(
SELECT manufacturers_id,
manufacturers_name,
manufacturers_image,
date_added,
last_modified
FROM manufacturers
ORDER BY manufacturers_name
) AS total
This happens also to some other categories in my website. All finish their line incomplete.
This query would do what you want:
SELECT COUNT(*) AS total
FROM manufacturers
What's wrong with your query:
COUNT() accepts an expression or single column as parameter - you're passing multiple
ORDER BY doesn't make much sense as soon as what you need is just number of rows (for obvious reason that number doesn't depend on order)
Maybe because the code is not on here full but what I can see is the mysql/mysqli_query is missing, and the ";" at the end of the code.