#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Johannesburg, South Africa
    Posts
    6
    Rep Power
    0

    Angry Creating Table in PostgreSQL using PHP


    I get a "parser: parse error at "(" on line... .... /path/to/script.php.

    on the following code:

    $db=pg_pconnect("dbname=my_db_name user=user_name") or die(pg_errormessage($db));
    $sql="CREATE TABLE users (
    id varchar(5),
    name varchar(20),
    middle varchar(20),
    last varchar(20),
    address varchar(50),
    expir date,
    pass varchar(20),
    PRIMARY KEY(id)
    )";
    pg_exec($db, $sql) or die(pg_errormessage());

    The error is on the LAST line of code above.

    This is driving me NUTS as I don't see any obvious error in the code. Please help.
    Last edited by dube; July 30th, 2001 at 05:30 AM.
  2. #2
  3. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    29
    I haven't used Postgresql much, but in other databases you have to explicitly declare all parts of the Primay Key to be NOT NULL. But it would seem to me that if this was the problem you would be getting a different type of error message. ????

    I don't see an obvious error in the code either.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Johannesburg, South Africa
    Posts
    6
    Rep Power
    0
    Thanks dcaillouet, but I have already tried ...(id varchar(5) NOT NULL, ...)"; still didn't work!!
  6. #4
  7. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Location
    Fly-over country
    Posts
    1,172
    Rep Power
    29
    Should this line

    pg_exec($db, $sql) or die(pg_errormessage());

    be like the line earlier in the code?

    pg_exec($db, $sql) or die(pg_errormessage($db));
  8. #5
  9. A PAtCHy sErver
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Italy
    Posts
    408
    Rep Power
    13
    I think it must be something like:

    $link = pg_exec($db, $sql)
    or die(pg_errormessage());
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2001
    Location
    Johannesburg, South Africa
    Posts
    6
    Rep Power
    0
    I finally got my PHP script(s) to work(creating tables). I found out when I declare NOT NULL it must be before the default value (if any)

    i.e. ident vachar(5) NOT NULL DEFAULT 0,

    and not:

    ident varchar(5) DEFAULT '0' NOT NULL,

    the default value must be without quotes.

IMN logo majestic logo threadwatch logo seochat tools logo