MySQL PHP dynamically add Column ALTER table to table

Source: Internet
Author: User
Tags mysql tutorial php tutorial

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
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.