Search code examples
phpmysqlportalcakephp-3.x

Database Error PDOException


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

screenshot of the error page for users table


Solution

  • 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