The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> PostgreSQL Help
|
Creating Table in PostgreSQL using PHP
Discuss Creating Table in PostgreSQL using PHP in the PostgreSQL Help forum on Dev Shed. Creating Table in PostgreSQL using PHP PostgreSQL Help forum discussing administration, SQL syntax, or other PostgreSQL-related topics. PostgreSQL provides enterprise level database functionality at open source prices.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 30th, 2001, 05:27 AM
|
|
Junior Member
|
|
Join Date: Jul 2001
Location: Johannesburg, South Africa
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
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.
|

July 30th, 2001, 09:30 AM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
|
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.
|

July 30th, 2001, 02:23 PM
|
|
Junior Member
|
|
Join Date: Jul 2001
Location: Johannesburg, South Africa
Posts: 6
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thanks dcaillouet, but I have already tried ...(id varchar(5) NOT NULL, ...)"; still didn't work!!
|

July 30th, 2001, 02:35 PM
|
 |
Big Endian
|
|
Join Date: May 2001
Location: Fly-over country
|
|
|
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));
|

July 31st, 2001, 01:33 PM
|
 |
A PAtCHy sErver
|
|
Join Date: Jun 2001
Location: Italy
Posts: 408
Time spent in forums: 2 m 27 sec
Reputation Power: 12
|
|
|
I think it must be something like:
$link = pg_exec($db, $sql)
or die(pg_errormessage());
|

August 4th, 2001, 09:14 AM
|
|
Junior Member
|
|
Join Date: Jul 2001
Location: Johannesburg, South Africa
Posts: 6
Time spent in forums: < 1 sec
Reputation 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|