creating table w/ php help
I'm very new to php and PostgreSQL. I keep getting the following error
when I try to create a table:
Warning: Wrong parameter count for pg_exec() in
/var/www/html/elkan/createtable.php on line 23
The table, ghdsl could not be created
Here is the code I'm using:
<?php
// set variables
$tablename = "ghdsl";
$dbname = "testingdb";
$user = "testinguser";
$password = "xxxxxx";
$connect = "pg_connect($dbname, $user, $password)";
$query = "CREATE table $tablename (id INT UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY, ip TEXT, customer TEXT, dslphone TEXT, date
TEXT, vpivci TEXT)";
if (pg_exec($dbname, $query, $connect))
{
print ("The table, $tablename was successfully created");
} else {
print ("The table, $tablename could not be created");
}
?>
thanks for any help.
thanks, that did it.
Cornelia Boenigk wrote:
Show quoted text
$query = "CREATE table $tablename (id INT UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY, ip TEXT, customer TEXT, dslphone TEXT,date
TEXT, vpivci TEXT)";
AUTO_INCREMENT is used in MySQL. With PostgreSQL you should use the
keyword SERIAL. Also UNSIGNED is not used.Here is the second problem. By looking at the php manual for the
pg-exec
function (changed to pg-query in php 4)
It *will* change from PHP 4.2.0 on. pg_exec() is still valid for all
releases < 4.2.0.Regards
Conni---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Import Notes
Reference msg id not found: Pine.LNX.4.33.0204191726100.22117-100000@blues.wcg.mcgill.caReference msg id not found: 002a01c1e7ee$835e1ba0$aec1fea9@zwerg98 | Resolved by subject fallback
On Fri, 19 Apr 2002, webmaster wrote:
Warning: Wrong parameter count for pg_exec() in
/var/www/html/elkan/createtable.php on line 23
The table, ghdsl could not be createdHere is the code I'm using:
<?php
// set variables
$tablename = "ghdsl";
$dbname = "testingdb";
$user = "testinguser";
$password = "xxxxxx";$connect = "pg_connect($dbname, $user, $password)";
Here is the first problem. $connect should be a resource, not a string.
Try this:
$connect = pg_connect ("dbname=$dbname user=$user
password=$password");
$query = "CREATE table $tablename (id INT UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY, ip TEXT, customer TEXT, dslphone TEXT, date
TEXT, vpivci TEXT)";if (pg_exec($dbname, $query, $connect))
Here is the second problem. By looking at the php manual for the pg-exec
function (changed to pg-query in php 4) I see that the correct usage is
pg_query (resource connection, string query)
Try changing your code to
if (pg_query($connect, $query))...
{
print ("The table, $tablename was successfully created");
} else {
print ("The table, $tablename could not be created");
}?>
If this doensn't work try consulting the online manual for php at
http://www.php.net/manual/en/
$query = "CREATE table $tablename (id INT UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY, ip TEXT, customer TEXT, dslphone TEXT,
date
TEXT, vpivci TEXT)";
AUTO_INCREMENT is used in MySQL. With PostgreSQL you should use the
keyword SERIAL. Also UNSIGNED is not used.
Here is the second problem. By looking at the php manual for the
pg-exec
function (changed to pg-query in php 4)
It *will* change from PHP 4.2.0 on. pg_exec() is still valid for all
releases < 4.2.0.
Regards
Conni