Doc Posted July 10, 2014 Share Posted July 10, 2014 I want to change various column names using: ALTER TABLE tablename CHANGE COLUMN oldname newname columntype; This is easy except for the last part (columntype). It seems silly to need to specify that since I don't want to change the column TYPE, only its name, but from what I've read, specifying columntype is mandatory. I need automated code, not show the table and manually view the columntype and manually input that. Thus I'd appreciate code that gives me $columntype. Thank you! Link to comment Share on other sites More sharing options...
Larry Posted July 10, 2014 Share Posted July 10, 2014 You can use `DESCRIBE tablename` and `SHOW COLUMNS FROM tablename` to find the column's current type. Link to comment Share on other sites More sharing options...
Doc Posted July 10, 2014 Author Share Posted July 10, 2014 I am still confused about what exact PHP code to use to get the column type into a string. Link to comment Share on other sites More sharing options...
Larry Posted July 11, 2014 Share Posted July 11, 2014 It may help to look online for similar solutions: https://www.google.com/search?q=mysql+get+column+type&gws_rd=ssl But these are all just queries that get executed, meaning you can fetch the results into a PHP variable just as you would a standard SELECT query. Link to comment Share on other sites More sharing options...
Recommended Posts