Re: creating table w/ php help

From: David A Dickson <davidd(at)saraswati(dot)wcg(dot)mcgill(dot)ca>
To: webmaster <webmaster(at)harbornet(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: creating table w/ php help
Date: 2002-04-19 21:33:13
Message-ID: Pine.LNX.4.33.0204191726100.22117-100000@blues.wcg.mcgill.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message wsheldah 2002-04-19 21:38:59 Re: Building perl mods pg:PG or DBD:PG on non
Previous Message Tom Lane 2002-04-19 21:28:03 Re: ROWTYPE as parameter to function