Re: creating table w/ php help - Mailing list pgsql-general

From David A Dickson
Subject Re: creating table w/ php help
Date
Msg-id Pine.LNX.4.33.0204191726100.22117-100000@blues.wcg.mcgill.ca
Whole thread Raw
In response to creating table w/ php help  (webmaster <webmaster@harbornet.com>)
List pgsql-general
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/


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: ROWTYPE as parameter to function
Next
From: wsheldah@lexmark.com
Date:
Subject: Re: Building perl mods pg:PG or DBD:PG on non