在SQL语法错误1064中更改表修改列查询结果

I get this error:

exception 'PDOException' with message '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 '(sfname2 VARCHAR(255) NOT NULL , slname2 VARCHAR(255) NOT NULL , ' at line 2'

When I try to run this query:

$stmnt = $db->prepare('ALTER TABLE eventfields MODIFY  
                       (sfname2 VARCHAR(255) NOT NULL ,
                       slname2 VARCHAR(255) NOT NULL ,
                       ....
                       customfield1 VARCHAR(255) NOT NULL ,)');

Why?

Get rid of the parenthesis around your columns and you need MODIFY COLUMN for each column being altered.

$stmnt = $db->prepare('ALTER TABLE eventfields   
                   MODIFY COLUMN sfname2 VARCHAR(255) NOT NULL ,
                   MODIFY COLUMN slname2 VARCHAR(255) NOT NULL ,
                   ....
                   MODIFY COLUMN customfield1 VARCHAR(255) NOT NULL ');