Reputation: 2501
I need to edit a field type in a MySQL table. Currently I have this one column set as VARCHAR that I need to change to an INT. The catch is that I do not have access to the control panel so I cannot simply flip the switch. How do I go about making this edit with PHP?
Upvotes: 4
Views: 1828
Reputation: 270637
Just execute an ALTER TABLE
statement
ALTER TABLE tablename MODIFY columnname INT;
In PHP:
$result = mysql_query("ALTER TABLE tablename MODIFY columnname INT;");
If you require extra attributes on that column, such as NOT NULL
, PRIMARY KEY
, or others, be sure to include them in the ALTER
statement, just after the data type INT
.
Upvotes: 7