SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating MySQL table on webpage

    Is it possible (using PHP), because there is function mysql_create_db()

  2. #2
    SitePoint Enthusiast spoorw8er's Avatar
    Join Date
    Oct 2001
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, it is.

    With mysql_create_db you can create a new database instance on the database host you connected to using mysql_connect.

    Then for creating the tables use mysql_query, supplying the correct SQL statements.

    e.g.(simplified code)
    PHP Code:
    //Connect to the host
    $link mysql_pconnect ("kron""jutta""geheim") or die ("Could not connect");

    // Create a new instance called my_db
    if (mysql_create_db ("my_db")) {
        print (
    "Database created successfully\n");

        
    // And now create a table in it
        
    $table mysql_query("CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20), species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);");
        if (
    $table) {
            print (
    "Table created succesfully\n");
        } else {
            
    printf ("Error creating table: %s\n"mysql_error ());
        }
    } else {  
        
    printf ("Error creating database: %s\n"mysql_error ());

    Hope it helps...

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, thats perfect:)

    But, because I have only 'webpage access' to my site, is it possible to output something like I can do on a command line:

    mysql>DESCRIBE tbl_name
    Last edited by sander_m; Oct 25, 2001 at 08:24.

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2001
    Location
    London
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql> CREATE TABLE table_name (
    -> column_1_name column_1_type column_1_details,
    -> column_2_name column_2_type column_2_details,
    -> ...
    -> );

    stealthen
    -- | StEaLThEn |--

  5. #5
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chances are you won't be able to use mysql_create_db().
    almost all virtual hosts disallow this as it'd allow you to create an unlimited number of databases.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  6. #6
    SitePoint Enthusiast jlgarcia's Avatar
    Join Date
    Sep 2001
    Location
    Baja California, México
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And when you have created a database this way, and some tables and everything is working fine, how do you let other people to update and consult this database but disallow them to create or delete the database or the tables?
    Use the source, Luke...

  7. #7
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make a form with the values you want them to be able to update, and when the form is submitted, insert these values to the appropriate table.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  8. #8
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would recommend against using mysql_create_db(). use mysql_query('CREATE DATABASE database') instead for consistency.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  9. #9
    SitePoint Guru
    Join Date
    Aug 2001
    Location
    Amsterdam
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    phpMyAdmin

    You probably have the same problem I had... Only FTP access.. well my ISP placed phpMyAdmin on the web with ofcourse a password protection...

    phpMyAdmin is a fairly easy program to manage your MySQL database and it accepts sql lines directly..

    Why not place that on your server??

    http://www.phpwizard.net/projects/phpMyAdmin/

    Good luck,

    Peanuts
    the neigbours (free) WIFI makes it just a little more fun


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
  •