SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding column into to mySQL

    I want to add a column into a database. I know that if I'm adding it manually into the database then I need to use ALTER TABLE, but how would I do it using PHP?
    Thanks

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Just like you read or insert data from your database. Execute the sql command (ALTER TABLE).

  3. #3
    SitePoint Enthusiast rgf207's Avatar
    Join Date
    Feb 2006
    Location
    Maryland
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    MYSQL_QUERY("ALTER TABLE table_name ADD (field_name  varchar(80) not null)); 

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried:
    PHP Code:
    mysql_select_db("people"$con);
    $sql "MYSQL_QUERY (ALTER TABLE contacts ADD (year varchar(50))");
    mysql_query($sql,$con);
    if (!
    mysql_query($sql,$con)) echo mysql_error();
    mysql_close($con);
    ?> 
    but just got an error message saying there was a problem with the code

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    mysql_select_db("people"$con); 
    $sql "ALTER TABLE contacts ADD (year varchar(50))"
    mysql_query($sql,$con) or die(mysql_error()); 
    mysql_close($con); 
    my mobile portal
    ghiris.ro


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •