I have a column named “read” in my table.
When I try to perform operations on it, PHP tells me there’s an error surround ‘read’. From previous experience with this kind of errors, I have determined that the column name ‘read’ is illegal.
The problem is that I can’t rename the column with PHP. Every time I try, I get an error (the same error, actually).
When I go in PHPMyAdmin, and change it there, it works perfectly afterwards.
Any ideas on how I can change the column name with PHP?
When you say “rename”, do you mean you’re trying to modify the table definition itself, like with
ALTER TABLE? If so, there shouldn’t be a difference between your PHP code and PHPMyAdmin (since the latter is itself just PHP code). The only problem you could run into is if you’re logging in as a different database user in your PHP code than you are in PHPMyAdmin. You need to make sure the user has ALTER privileges on that table.If you’re only talking about running normal queries on the table, and just want to stop the syntax error from occurring, then you can just wrap your field and/or table names in backticks – i.e. ` usually on the same key as the tilde ~ on the number bar – and MySQL will be able to distinguish between the field name and the reserved word.