pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
problems when fetching array contents.
4+ messages / 4 participants
[nested] [flat]

* problems when fetching array contents.
@ 2003-08-13 17:18  Jonas Vonlanthen <j.vonlanthen@jef.ch>
  0 siblings, 0 replies; 4+ messages in thread

From: Jonas Vonlanthen @ 2003-08-13 17:18 UTC (permalink / raw)
  To: pgsql-php

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");

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

The problem I have is that although it passed through the while LOOP the
right number of times (= the number of entries in the table), I'm not
able to print any key or value (when I test using "echo
$configuration['cfgKey']..., it just writes nothing), and the php
constants are therefore not defined.
"configuration_key" and "configuration_value" are varchar(64)

Any one knows how to handle this? I'm using postgre 7.3.2 and php 4.3.1.

Thanks in advance,
Best Regards.

Jonas Vonlanthen




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* problems when fetching array contents.
@ 2003-08-13 17:24  J0nEz <jonas@frizone.ch>
  0 siblings, 2 replies; 4+ messages in thread

From: J0nEz @ 2003-08-13 17:24 UTC (permalink / raw)
  To: pgsql-php

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");

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

The problem I have is that although it passed through the while LOOP the
right number of times (= the number of entries in the table), I'm not
able to print any key or value (when I test using "echo
$configuration['cfgKey']..., it just writes nothing), and the php
constants are therefore not defined.
"configuration_key" and "configuration_value" are varchar(64)

Any one knows how to handle this? I'm using postgre 7.3.2 and php 4.3.1.

Thanks in advance,
Best Regards.

Jonas Vonlanthen




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: problems when fetching array contents.
@ 2003-08-13 17:48  Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
  parent: J0nEz <jonas@frizone.ch>
  1 sibling, 0 replies; 4+ messages in thread

From: Cornelia Boenigk @ 2003-08-13 17:48 UTC (permalink / raw)
  To: J0nEz <jonas@frizone.ch>; pgsql-php

Hi

>  while ($configuration = tep_db_fetch_array($configuration_query)) {

Why don't you use pg_fetch_array() or pg_fetch_assoc() or
pg_fetch_all()?

Conni




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: problems when fetching array contents.
@ 2003-08-13 18:17  cmr@shell.gis.net
  parent: J0nEz <jonas@frizone.ch>
  1 sibling, 0 replies; 4+ messages in thread

From: cmr@shell.gis.net @ 2003-08-13 18:17 UTC (permalink / raw)
  To: pgsql-php

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-08-13 18:17 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-13 17:18 problems when fetching array contents. Jonas Vonlanthen <j.vonlanthen@jef.ch>
2003-08-13 17:24 problems when fetching array contents. J0nEz <jonas@frizone.ch>
2003-08-13 17:48 ` Cornelia Boenigk <poppcorn@cornelia-boenigk.de>
2003-08-13 18:17 ` cmr@shell.gis.net

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