create mysql table code

Discussion in 'PHP' started by raven2424, Dec 24, 2005.

  1. #1
    hello i need the mysql code to create a table to put this code into


    INSERT INTO `mos_categories`
    (`title`, `name`, `section`, `image_position`, `description`, `published`, `checked_out`, `checked_out_time`, `editor`, `ordering`, `access`, `count`) VALUES
    ('Coctails', 'Coctails', 'com_garyscookbook', 'left', 'Your first Recipe category.', 1, 0, '0000-00-00 00:00:00', NULL, 1, 0, 0);

    when i use this code it says table not found so i need the code to go aboce it that will make the table and then insert this stuff
     
    raven2424, Dec 24, 2005 IP
  2. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In order to give you the proper syntax to create the table and fields, we would need to know what each field type is. We can guess what each field's data type is based on the values you mention, but it could fail completely if those guesses are incorrect.
     
    tflight, Dec 24, 2005 IP
  3. raven2424

    raven2424 Well-Known Member

    Messages:
    754
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    160
    #3
    hmm icic mainly i was installing a script and i needed to create a table and then add those rows i belive
     
    raven2424, Dec 25, 2005 IP
  4. l234244

    l234244 Peon

    Messages:
    1,225
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
  5. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, you can create the table just with:

    CREATE TABLE `mos_categories`;

    However that will not create and define the fields. So then when you run that insert statement it will not work since the named fields have not been defined. So the process normally goes (1) create the table, (2) define the field names and types, then (3) populate the data.

    You have the pieces to complete steps 1 and 3, but step 2 is missing. Some of step 2 could be guessed, however some of the data types are not obvious based on the dataset.
     
    tflight, Dec 25, 2005 IP
  6. himambo

    himambo Peon

    Messages:
    100
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    himambo, Dec 26, 2005 IP
  7. dotcommakers

    dotcommakers Active Member

    Messages:
    286
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    after 15 min's hard work here is code :)

     
    dotcommakers, Dec 26, 2005 IP
  8. tflight

    tflight Peon

    Messages:
    617
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    0
    #8
    There is a small chance that would work, but it isn't likely. You've assumed that all of the fields are varchar. You can't make that assumption.

    For example check_out_time is obviously either a datetime or timestamp field, most of the last few fields are either ints, enums, etc. They are porbably not varchar fields. There might be certain fields that are indexed, certain fields that require not null data, the description field might need to be longer than you have allocated, and the script this person is using might use InnoDB table types.
     
    tflight, Dec 26, 2005 IP
  9. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    With the base for the script i think raven could make the changes needed.
     
    onlyican.com, Dec 26, 2005 IP
  10. dotcommakers

    dotcommakers Active Member

    Messages:
    286
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #10
    everything will work if there is int but for date field he has to make changes.. but i have provided good info may be he will be able to change or if he request i will do it
     
    dotcommakers, Dec 26, 2005 IP