Re: problems when fetching array contents.

Поиск
Список
Период
Сортировка
От cmr@shell.gis.net
Тема Re: problems when fetching array contents.
Дата
Msg-id 20030813181752.GA16982@ssbeagle
обсуждение исходный текст
Ответ на problems when fetching array contents.  ("J0nEz" <jonas@frizone.ch>)
Список 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

В списке pgsql-php по дате отправления:

Предыдущее
От: "J0nEz"
Дата:
Сообщение: error was in last email: problems when fetching array contents.
Следующее
От: "Jonas Vonlanthen"
Дата:
Сообщение: problems when fetching array contents.