SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Create Mutiple Tables

    Heyo,

    I currently have the following code to create a database + table,
    how do I amend the code to create two tables inside the database?

    Code PHP:
    <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
    {
      die('Could not connect: ' . mysql_error());
    }
     
    // Create database
    if (mysql_query("CREATE DATABASE Users",$con))
    {
      echo "Database created!";
    }
    else
    {
      echo "Error creating database: " . mysql_error();
    }
     
    // Create table in WB database
    mysql_select_db("Users", $con);
    $sql = "CREATE TABLE Records 
    (
      id int not null auto_increment,
      username text,
      password text,
      primary key(id)
    )";
    mysql_query($sql,$con);
     
    mysql_close($con);
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    619
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you just use phpmyadmin and do it the easy way?

    Are you writing a script that will do this for you?

  3. #3
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adnasium View Post
    why don't you just use phpmyadmin and do it the easy way?

    Are you writing a script that will do this for you?
    Yes, the code attached to my previous post, create a database with one table, how do I create a database with two?

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    619
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whats the problem with doing this?


    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","peter","abc123");
    if (!
    $con)
    {
      die(
    'Could not connect: ' mysql_error());
    }
     
    // Create database
    if (mysql_query("CREATE DATABASE Users",$con))
    {
      echo 
    "Database created!";
    }
    else
    {
      echo 
    "Error creating database: " mysql_error();
    }
     
    // Create table in WB database
    mysql_select_db("Users"$con);
    $sql "CREATE TABLE Records
    (
      id int not null auto_increment,
      username text,
      password text,
      primary key(id)
    )"
    ;
    mysql_query($sql,$con);

    // Create table in WB database
    mysql_select_db("Users"$con);
    $sql "CREATE TABLE Records
    (
      id int not null auto_increment,
      username text,
      password text,
      primary key(id)
    )"
    ;
    mysql_query($sql,$con);
     
    mysql_close($con);
    ?>

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    619
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You would just change the last part to create the table you want. All you are doing is executing a query.

  6. #6
    Non-Member
    Join Date
    Jun 2007
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What last part?


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
  •