简体   繁体   中英

How do I edit MySQL table column properties with PHP?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM