Medoo icon indicating copy to clipboard operation
Medoo copied to clipboard

ALTER TABLE issue on $db->query()

Open iamahmadahmadi opened this issue 3 years ago • 2 comments

Hey there, I tried to change a column type from INT to VARCHAR and I used this command, but I got no result/error. $db->query("ALTER TABLE tablename CHANGE balance balance VARCHAR(300) NOT NULL;"); Would you please help me out? Thanks.

iamahmadahmadi avatar Feb 09 '22 16:02 iamahmadahmadi

Make sure your query is correct.

/* MySQL */
ALTER TABLE table_name RENAME COLUMN old_name TO new_name;
/* MariaDB */
ALTER TABLE table_name CHANGE COLUMN old_name TO new_name;

catfan avatar Feb 11 '22 05:02 catfan

The above answer is supported on MySQL 8.0.

Just make sure the database can execute the query successfully based on the version. Because query() is just executing the query alone for the database.

catfan avatar Feb 11 '22 06:02 catfan