SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2000
    Location
    Sydney, Australia
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Everyone,

    I've been trying to create a table in MS Access with PHP/Apache using ODBC.

    I can create a simple table, but the problem is when I add the PRIMARY KEY attribute to the ir_no field it returns an error.

    The SQL code is as follows:

    Code:
    		$sql = "CREATE TABLE Incident (" .
    		"ir_no INT PRIMARY KEY, " .
    		"vendor_incident_no INT, " .
    		"date_raised DATE NOT NULL, " .
    		"short_desc TEXT, " .
    		"review_comments TEXT, " .
    		"raised_by INT NOT NULL, " .
    		"severity INT NOT NULL, " .
    		"application INT NOT NULL, " .
    		"priority INT NOT NULL, " .
    		"status INT NOT NULL " .
    		")";
    
    		$cur = odbc_exec( $cnx, $sql );
    When I take out the PRIMARY KEY attribute, it works fine! But as soon as I add it back, no joy. It's enough to make you cry!

    Also, I want the ir_no field to be auto incremented. I tried adding the AUTO_INCREMENT attribute to the ir_no field, but again it didn't like the SQL statement.

    What am I doing wrong???

    Thanks, and merry Christmas!

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you need to use this statement:
    Code:
    CREATE TABLE Incident (ir_no INT AUTO_INCREMENT, vendor_incident_no INT , date_raised DATE not null , short_desc TEXT , review_comments TEXT , raised_by INT not null , severity INT not null , application INT not null , priority INT not null , status INT not null , PRIMARY KEY (ir_no))
    Hope that helps

  3. #3
    SitePoint Member
    Join Date
    Jul 2000
    Location
    Sydney, Australia
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried that variation as well... Still no luck!

    It returns the following error message when I include one of the AUTO_INCREMENT or PRIMARY KEY attributes (or both at the same time).

    Code:
    Warning: SQL error: [Microsoft][ODBC Microsoft Access 97 Driver] Syntax error in CREATE TABLE statement.,
    SQL state 37000 in SQLExecDirect
    For some reason it doesen't like either one of these attributes. Very frustrating!


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
  •