SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySql: Creating Tables

    how do i create a table for mysql db
    without using SSH
    or Phpmyadmin?
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW

  2. #2
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW

  3. #3
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can do it with a php script.

    something like:
    PHP Code:
    $create_sql "CREATE TABLE users (user_id INT (4) not null , username VARCHAR (32) not null , email VARCHAR (32) , PRIMARY KEY (user_id), UNIQUE (user_id))";
    if(!
    $create_sql)
    {
      echo 
    mysql_error();
      exit;

    That'll create a table called users with 3 fields:
    user_id which is a number, 4 characters long, not null (null means empty)
    username which is a character field, 32 char. long, not null
    and email which is a character field, 32 long, and can be null.

    PRIMARY KEY makes the field in the () the primary key of the table, and UNIQUE specifies a field that can't be duplicated.

    If for some reason the query fails it'll echo out the mysql error that cased the failure.
    Defender's Designs
    I'm Getting Married!

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

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also, here's mysql's support page for create table:
    http://www.mysql.com/doc/C/R/CREATE_TABLE.html
    Defender's Designs
    I'm Getting Married!

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

  5. #5
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Error
    SQL-query : [Edit]

    CREATE TABLE `users` (`user_id` INT(4) NOT NULL, `user_name` TEXT(32) NOT NULL, `email` TEXT(32) , PRIMARY KEY (`user_id`), UNIQUE (`user_id`)) comment = 'Training'

    MySQL said:


    You have an error in your SQL syntax near '(32) NOT NULL, `email` TEXT(32) , PRIMARY KEY (`user_id`), UNIQUE (`user_id`)) c' at line 1
    what's the prob here?
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW

  6. #6
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm not expert on the exact syntax, but why are you using the accent marks (`) around the field names?

    I've created many tables fine w/o the use of them.

    also, try moving the comment into the parentheses and see if that helps.
    Defender's Designs
    I'm Getting Married!

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

  7. #7
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Defender1
    i'm not expert on the exact syntax, but why are you using the accent marks (`) around the field names?
    This is from phpMyAdmin

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  8. #8
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh, if he's using phpmyadmin, why does he want the code to do it?
    Defender's Designs
    I'm Getting Married!

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

  9. #9
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried it myself, but i had no results....so i gave it a go in the admin thing......it works now
    but i want to learn MySql without the use of the admin
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW

  10. #10
    SitePoint Zealot sonique's Avatar
    Join Date
    Sep 2001
    Location
    Missouri [U.S.]
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also....
    when i look at tut's it tells me to use a secure shell program.....which i don't want to do...
    jmulder[THE MENTOR]'s nice guy online!
    Rig: AMD Athlon 800mhz; 384mb SDRam; 32mb nVidia @ 1024x768; ie 6; Windows ME; 15 gig; Cd-RW

  11. #11
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You get an error if you make column names with quotes around them, dispite what phpMyAdmin shows you.


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
  •