pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: cmr@shell.gis.net
To: pgsql-php@postgresql.org
Subject: Re: problems when fetching array contents.
Date: Wed, 13 Aug 2003 14:17:52 -0400
Message-ID: <20030813181752.GA16982@ssbeagle> (raw)
In-Reply-To: <000401c361bf$b2b378e0$2201a8c0@naboo>
References: <000401c361bf$b2b378e0$2201a8c0@naboo>

On Wed, Aug 13, 2003 at 07:24:03PM +0200, J0nEz wrote:
> Hello,
> 
> I'm having problems fetching array contents.
> 
> Connection to my db is alright, the db data too.
> 
> Here is the problem:
> 
> I have a table named "configuration" containing Keys and Values of
> Constants that have to be defined in php.
> 
> The code:
> 
> $configuration_query = pg_query("select configuration_key as cfgKey,
> configuration_value as cfgValue from configuration");
> 

If this is your actual code, you are not passing the connection resource
variable to pg_query.
 (see here: http://us4.php.net/manual/en/function.pg-query.php )

>   while ($configuration = tep_db_fetch_array($configuration_query)) {
>     echo $configuration['cfgKey']; $configuration['cfgValue'];  // test
>     define($configuration['cfgKey'], $configuration['cfgValue']);
>   }
> 

I would do a pg_fetch_array, and then foreach through the array like
this:

 $query_rows = pg_num_rows($resource_from_pg_query);
 for($iterator = 0; $iterator < $query_rows; $iterator++)
 {
   $my_db_array = pg_fetch_array($resource_from_pg_query)
   foreach ($my_db_array as $mdba_name => $mdba_value)
   {
     define("$mdba_name", "$mdba_value");
   }
 }


then a print_r(get_defined_vars) should give you your vars..

Hope this helps!

Chadwick



view thread (4+ messages)

Message-ID: <20030813181752.GA16982@ssbeagle>
Permalink:  ../20030813181752.GA16982@ssbeagle/
Also on:    postgresql.org/message-id/20030813181752.GA16982@ssbeagle

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: cmr@shell.gis.net
  Subject: Re: problems when fetching array contents.
  In-Reply-To: <20030813181752.GA16982@ssbeagle>
  References: <000401c361bf$b2b378e0$2201a8c0@naboo> <20030813181752.GA16982@ssbeagle>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox