MySQL Tutorial PHP tutorial dynamically add Column ALTER table to table
Add the MySQL statement of the column as
ALTER TABLE tablename ADD COLUMN columnName varchar () 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 column programs
/*
OK, look at the table structure of the Insert list
ID Int (8) No auto_increment
Title char (UTF8_GENERAL_CI) is NULL
Content Text Utf8_general_ci
*/
$column = ' Addnewcolumn ';
$sql = "ALTER TABLE test ADD COLUMN $column varchar NOT NULL";
if (mysql_query ($sql))
{
Echo ' successful operation ';
}
Else
{
Echo mysql_error ($conn);
}
/*
After successful operation
ID Int (8) No auto_increment
Title char (UTF8_GENERAL_CI) is NULL
Content Text Utf8_general_ci is NULL
Addnewcolumn varchar () utf8_general_ci No
Operation failed if provided
Duplicate column name ' Addnewcolumn '
It is proved that Addnewcolumn has already existed.
*/
This article original in www.111cn.net reprint to indicate the origin
?>