Thread: creating table w/ php help

creating table w/ php help

From
webmaster
Date:
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.




Re: creating table w/ php help

From
David A Dickson
Date:
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 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)";

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/


Re: creating table w/ php help

From
"Cornelia Boenigk"
Date:
> $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


Re: creating table w/ php help

From
webmaster
Date:
thanks, that did it.

Cornelia Boenigk wrote:

> > $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