Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2004
    Posts
    494

    Unanswered: problem creating table in an existing db

    I have a db open but have a problem creating a table:

    PHP Code:
    // Create table in my_db database
    mysql_select_db("kjv"$con);
    $sql2 "CREATE TABLE person ( 
    PRIMARY KEY(id) smallint, 
    recordType char, 
    book_title, 
    book smallint, 
    chapter smallint, 
    verse smallint, 
    book_spoke smallint, 
    chapter_spoke smallint, 
    verse_spoke smallint, 
    text_data longtext
    )"
    ;
    mysql_query($sql2,$con); 
    Compare bible texts (and other tools):
    TheWheelofGod

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you did not say what the problem is

    never mind, i can see a few things wrong

    PRIMARY KEY(id) smallint should be id smallint PRIMARY KEY

    recordType char should be recordType char(1)

    book_title should be book_title varchar(55)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2004
    Posts
    494
    it says:
    Error: Table 'kjv.person' doesn't exist
    kjv is supposed to be the existing database which is open.

    I got my example from
    http://www.w3schools.com/php/php_mysql_create.asp
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","peter","abc123");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    // Create database
    if (mysql_query("CREATE DATABASE my_db",$con))
      {
      echo 
    "Database created";
      }
    else
      {
      echo 
    "Error creating database: " mysql_error();
      }

    // Create table in my_db database
    mysql_select_db("my_db"$con);
    $sql "CREATE TABLE person 
    (
    FirstName varchar(15),
    LastName varchar(15),
    Age int
    )"
    ;
    mysql_query($sql,$con);

    mysql_close($con);
    ?>
    Except that I thought I should delete part of it because I don't intend to create a NEW database and the database is already open.
    My intention is to insert data from one table to the other ( created table ).
    Compare bible texts (and other tools):
    TheWheelofGod

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    just out of curiosity has the userid you are using in the script got adequate permissions for this task?

    what is the actual MySQL error message?

    in development mode I tend to use the "or die" construct on my MySQL interface code

    or die( echo "<some other debug data.... telling me what script, what action I was taking, an internal erro number etc.....>".mysql_errno().": ".mysql_error());

  5. #5
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    Log into MySQL command line using the credentials you are currently providing in your php script. Then execute the same queries to create the db and table. Then do a "SHOW TABLES" and see if that table has been created. I would guess and say that you haven't created the table successfully, either because of permissions or otherwise.

Posting Permissions

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