#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    66
    Rep Power
    14
    Hi,

    Is it possible to create a table through PHP? ie not by Telnet or phpMyAdmin?

    If so, could someone post a small example?

    Thanks,

    ~ AoErat
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    You can send ANY mysql query via the mysql_query() function.

    mysql_query("create table foo.....");

    You can use any query just as you'd use it on the command line except you have to escape double quotes.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    66
    Rep Power
    14
    So, am I right to assume that the following would work?

    <?php

    mysql_connect (localhost, username, password);

    mysql_select_db (dbname);

    $sql = "CREATE TABLE test(username CHAR(10) NOT NULL, password CHAR(60) NOT NULL, PRIMARY KEY(ID))";

    $result = mysql_query($sql);
    if (!$result){
    print mysql_error();
    exit;
    }

    php?>

    Thanks.


    [This message has been edited by AoErat (edited November 11, 2000).]
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    No, it wouldn't.....

    ID is not defined so you can't make it your primary key.

    Other than that it'll work fine.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    66
    Rep Power
    14
    Ok, whatever.

    Thanks a lot!

Similar Threads

  1. Creating a table using SELECT
    By gdjsmith in forum Database Management
    Replies: 1
    Last Post: February 11th, 2004, 04:05 PM
  2. how to keep table on top, not centered??
    By vinyl in forum HTML Programming
    Replies: 2
    Last Post: January 20th, 2004, 06:19 PM
  3. creating table from vb
    By nebujacob2000 in forum Database Management
    Replies: 1
    Last Post: January 6th, 2004, 12:02 PM
  4. Creating a MySQL table. errno: 140
    By WorldBuilder in forum MySQL Help
    Replies: 1
    Last Post: December 18th, 2003, 02:43 PM
  5. problem creating a table
    By iso in forum MySQL Help
    Replies: 2
    Last Post: December 11th, 2003, 11:18 AM

IMN logo majestic logo threadwatch logo seochat tools logo