Reputation: 1
whats my problem to add new columns to DB
// Connection
global $tutorial_db;
$tutorial_db = new mysqli();
$tutorial_db->connect($dbhost, $dbuser, $dbpass, $dbname);
$tutorial_db->set_charset("utf8");
// Check Connection
if ($tutorial_db->connect_errno) {
printf("Connect failed: %s\n", $tutorial_db->connect_error);
exit();
}
$query="alter table groups add order varchar (20)";
$result = $tutorial_db->query($query);
This code doesn't do anything...
Upvotes: 0
Views: 107
Reputation: 150
ALTER TABLE `table_name` add COLUMN `column_name` VARCHAR(20);
Please note the backticks. They are important to escape the column name, especially if you wish to call your column order as that is already a reserve word in mysql and has it's own meaning.
Upvotes: 0
Reputation: 284
I suspect it's because your column is called 'order', which is an SQL keyword. If you really want to call it order, enclose it with backticks -
$query="alter table groups add `order` varchar (20)";
But I'd recommend you call it something else if you can.
Upvotes: 0
Reputation: 781058
ORDER
is a reserved word, you need to quote it with backticks, or use a different name for the column.
$query="alter table groups add `order` varchar (20)";
Upvotes: 3