April 2026
Intermediate
1009 pages
34h 15m
English
The example here is the same as in all other database chapters; the differences are in the details.
The table is created as usual by calling CREATE TABLE. It should also be noted here that the special PostgreSQL data type SERIAL is used for the autovalue.
<?php if ($db = pg_connect("host=localhost port=5432 dbname=PHP user=postgres password=pwd.")) { $sql = "CREATE TABLE guestbook ( id SERIAL PRIMARY KEY, heading VARCHAR(1000), entry VARCHAR(8000), author VARCHAR(50), email VARCHAR(100), date TIMESTAMP )"; if (pg_query($db, $sql)) { echo "Table created.<br />"; } else { echo "Error: " . pg_last_error() . "!"; } pg_close($db); } else { echo "Error!"; }?>
Listing 23.13 The Table Is Created ...
Read now
Unlock full access