dbTalk Databases Forums  

Querying the system catalog

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Querying the system catalog in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Marcel Wolf
 
Posts: n/a

Default Querying the system catalog - 01-27-2004 , 04:07 PM






Hello group
I am trying to follow through on advice I received from you earlier. I
would like to check for my database when I logon and if it is not there
create it( I am using php to write web apps). I am able to connect to
the template1 and query for pg_database. But I am getting a parse error
on the following (XXX).

Error message:
"Expected T_STRING or T_VARIABLE"



Code :
$link=pg_connect('user=marcel dbname=template1') or die ("Couldn't
connect to template1 try again.<br>");

$query = "SELECT * FROM pg_database";

$result = pg_query ($query) or die ("Couldn't get the
database names".pg_last_error());

// If it worked get the database names.

$database= pg_fetch_array ($result) or print ("Can't get the
array of databases<br>");

XXX print (" the 1st database is $database['datname'].<br>");

die ("Finshed my test.<br>");

Is this the correct way to query the system catalog for the existing
databases? Is this questions addressed to the wrong group and maybe
should be addressed to the php_pgsql group?
Again thanks for the help
Marcel Wolf


Reply With Quote
  #2  
Old   
Bruno LEVEQUE
 
Posts: n/a

Default Re: Querying the system catalog - 01-27-2004 , 04:30 PM






Hi,

I am not a guru of php, so ...

But, if it can help you, here is a little code I use :

$conn=pg_connect("host=localhost user=bruno dbname=agenda");
if (!$conn) {
echo "Couldn't connect to agenda.<BR>";
exit;
}

$query="SET DATESTYLE TO PostgreSQL,European";
# execution de la requete
pg_query($conn, $query);

$query="SELECT * from agenda ";

# execution de la requete
$result = pg_query($conn, $query);

$arr = pg_fetch_all($result);

for ($i=0; $i<$NbLigne;$i++)
{
if ($arr[$i]["heures"] == ....
.....
and so


Bruno

On Tue, 27 Jan 2004, Marcel Wolf wrote:

Quote:
Hello group
I am trying to follow through on advice I received from you earlier. I
would like to check for my database when I logon and if it is not there
create it( I am using php to write web apps). I am able to connect to
the template1 and query for pg_database. But I am getting a parse error
on the following (XXX).

Error message:
"Expected T_STRING or T_VARIABLE"



Code :
$link=pg_connect('user=marcel dbname=template1') or die ("Couldn't
connect to template1 try again.<br>");

$query = "SELECT * FROM pg_database";

$result = pg_query ($query) or die ("Couldn't get the
database names".pg_last_error());

// If it worked get the database names.

$database= pg_fetch_array ($result) or print ("Can't get the
array of databases<br>");

XXX print (" the 1st database is $database['datname'].<br>");

die ("Finshed my test.<br>");

Is this the correct way to query the system catalog for the existing
databases? Is this questions addressed to the wrong group and maybe
should be addressed to the php_pgsql group?
Again thanks for the help
Marcel Wolf

Bruno LEVEQUE
System Engineer
SARL NET6D
bruno.leveque (AT) net6d (DOT) com
http://www.net6d.com

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster



Reply With Quote
  #3  
Old   
Andre Dubuc
 
Posts: n/a

Default Re: Querying the system catalog - 01-27-2004 , 05:23 PM



Hi Marcel,

I believe your error is a result of lack of braces around
$database['datname']. Try:

print (" the 1st database is {$database['datname']}.<br>");

Hth,
Andre

On Tuesday 27 January 2004 05:07 pm, you wrote:
Quote:
Hello group
I am trying to follow through on advice I received from you earlier. I
would like to check for my database when I logon and if it is not there
create it( I am using php to write web apps). I am able to connect to
the template1 and query for pg_database. But I am getting a parse error
on the following (XXX).

Error message:
"Expected T_STRING or T_VARIABLE"



Code :
$link=pg_connect('user=marcel dbname=template1') or die ("Couldn't
connect to template1 try again.<br>");

$query = "SELECT * FROM pg_database";

$result = pg_query ($query) or die ("Couldn't get the
database names".pg_last_error());

// If it worked get the database names.

$database= pg_fetch_array ($result) or print ("Can't get the
array of databases<br>");

XXX print (" the 1st database is $database['datname'].<br>");

die ("Finshed my test.<br>");

Is this the correct way to query the system catalog for the existing
databases? Is this questions addressed to the wrong group and maybe
should be addressed to the php_pgsql group?
Again thanks for the help
Marcel Wolf

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.