0

I want to add some columns in to existing database table after the last column i want to add these.. the scritp will be avalaible for everyone so not sure what will be the last column.

$DB_Column = array (
        'About_Me' => "About", 
        'Avatar' => "Avatar",
        'Clan_Tag' => "Clan",
        'Month' => "Month",
        'Day' => "Day",
        'Year' => "Year",
        'Website' => "Website",
        'Website_Link' => "Link",
        'Website_Link1' => "Link1",
        'Email_Address' => "Email"
    );

$Database->exec('ALTER TABLE '.$DB_Table.' 

            ADD COLUMN '.$DB_Column['About_Me'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Avatar'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Clan_Tag'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Month'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Day'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Year'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Website'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Website_Link'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Website_Link1'].' VARCHAR(255),
            ADD COLUMN '.$DB_Column['Email_Address'].' VARCHAR(255) 
    ');

Getting this error:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 near ",": syntax error' in C:\xampp\htdocs\Webstats\Functions.php:30 Stack trace: #0 C:\xampp\htdocs\Webstats\Functions.php(30): PDO->exec('ALTER TABLE RCO...') #1 C:\xampp\htdocs\Webstats\Index.php(3): require('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\Webstats\Functions.php on line 30

2 Answers 2

1

The ALTER TABLE statement allows only one column.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh really? not at all we can add multiple columns!
@JavedAhmadzai:- How can you be so sure?Did you check the document of sqlite?
0

You cannot add more than one column using alter table command.

enter image description here

12 Comments

@JavedAhmadzai:- Did you checked that it is a MYSQL not SQLITE! In MySql it is allowed but not in Sqlite:)
@JavedAhmadzai:- No it is not possible in Sqlite! :( you need to have repeated calls to ALTER TABLE.
Well, repeating alter table is not bad but what about AFTER i want automatic last column to be selected and new column to be added after last one! can it be>?
@JavedAhmadzai:- I am not sure what exactly you are trying to achieve. I would suggest you may better ask a new question if that is a different issue :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.