Mysql tutorial php tutorial Add a column alter table to the TABLE dynamically
The mysql statement for adding columns is
Alter table tableName add column columnName varchar (20) not null
*/
// Database tutorial connection method
$ Db = '111cnnet ';
$ Conn = mysql_pconnect ('localhost', 'root', 'root') or die (mysql_error ());
Mysql_select_db ($ db, $ conn );
// Start adding a column Program
/*
Row to see the table structure of the inserted list
Id int (8) No auto_increment
Title char (150) utf8_general_ci is NULL
Content text utf8_general_ci
*/
$ Column = 'addnewcolumn ';
$ SQL = "ALTER TABLE test ADD COLUMN $ column varchar (20) not null ";
If (mysql_query ($ SQL ))
{
Echo 'Operation successful ';
}
Else
{
Echo mysql_error ($ conn );
}
/*
After the operation is successful
Id int (8) No auto_increment
Title char (150) utf8_general_ci is NULL
Content text utf8_general_ci is NULL
AddNewColumn varchar (20) utf8_general_ci No
Operation failed if
Duplicate column name 'addnewcolumn'
It proves that addNewColumn already exists.
*/
// This article was originally posted on www. bKjia. c0m and indicated the source
?>