Entity icon indicating copy to clipboard operation
Entity copied to clipboard

MySQL error and table name escaping

Open sigaryov opened this issue 1 year ago • 0 comments

If there is a table in the database with a reserved name (for example, groups), then I get an 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 'groups' at line 1 (Connection: mysql, SQL: SHOW COLUMNS FROM groups;)

Change src/MySQL.php and add name escaping:

'fields' => \DB::select("SHOW COLUMNS FROM `{$name}`;"),
'indexes' => \DB::select("SHOW INDEX FROM `{$name}`;"),

sigaryov avatar Jun 30 '23 13:06 sigaryov