Custom Web Applications to Grow Your Business

(256) 429-8145

Mysql php command for add delete alter columns and tables

There are so many php and mysql functions, tips and tricks that it is literally impossible for the average developer to remember every code when programming. When I am working on tables and columns PhpMyAdmin or just from straight php pages I sometimes have to revert to books or online sources for the right syntax etc. So I am putting a few example here as a reference: To delete the column ALTER TABLE table DROP col Copying info from one table to another $results = mysql_query ("SELECT * FROM table1"); if (!$results) { exit (error); } while ($row = mysql_fetch_array($results)) { $ID = $row['ID']; $col1 = $row['col1']; $sql = mysql_query("UPDATE table2 SET col2 = '$col1' WHERE ID = '$ID'"); if (!$sql) { exit ("Error updating details: " . mysql_error(). ""); } else { } } ?> Inserting column from table to the next Insert into table (col1) SELECT col2 from table2 How to rename mysql table Rename table table1 to table2 Adding column to table ALTER table table1 ADD column col1 varchar (255) NULL; Updating column in one table with data from other column in other table UPDATE table1 ,table2 SET table2.col1 = table1.col1 WHERE ...... Merge data from 2 columns in same table UPDATE post SET col1 = CONCAT(col2,col3)