Re: php + postgresql

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: php + postgresql
Дата
Msg-id 48885496.4050604@postnewspapers.com.au
обсуждение исходный текст
Ответ на php + postgresql  (admin <mick@mjhall.org>)
Список pgsql-general
admin wrote:
> First, thanks to everyone who responded to my newbie questions
> yesterday, all clear now.
>
> I spent most of today struggling with apparently inconsistent behaviour
> while running SELECT statements on PG 8.1.9 using PHP 5.1.6 (these are
> both as supplied with CentOS 5.1, a fairly conservative distro).
>
> It seems that some of PHP's PG functions have changed recently, are
> there any known issues with them?
>
> 1.
> I ended up using pg_prepare() and pg_execute() as pg_query() alone just
> didn't seem to work. But SELECT statements seemed to be cached or
> persistent in some way, such that they "lived" beyond the life of the
> PHP script. Is there something I need to know about persistent behaviour
> in PG that doesn't exist in MySQL?

It sounds like you must be using a connection pooler, so your scripts
are acquiring connections that've already been used and had statements
prepared for them. If you try to prepare a new statement with the same
name it'll fail.

I understand that this is a common issue with simple connection poolers,
but as I don't deal with them myself I don't have any suggestions for
you. Others here may, and I'm sure Google can help out too.

> 3.
> Some examples I found used PHP's pg_num_rows() function to count the
> rows in a result, then iterated through them with a "for" loop ... is
> this required behaviour (PHP docs don't appear to discuss this)?

Required by what? I'm not sure I really understand your question.

Do you mean "does PostgreSQL always return a row count that can then be
accessed with pg_num_rows()" ?

Or:

"Must I iterate through a resultset with a loop over pg_num_rows()
rather than using some other method to iterate through the resultset" ?

> 4.
> Another weird one was that this statement always failed:
>
> $name = "file.php";
> SELECT fld_content FROM tbl_page WHERE fld_name='$name'

"failed" how? What did you expect to happen? What happened instead? What
was the exact error message?

You always need to ask yourself those questions when reporting any sort
of problem. Otherwise, the people reading your question will just have
to ask them, so you'll get slower and less useful responses (and fewer
of them, as many people will just ignore poorly written questions).

--
Craig Ringer

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

Предыдущее
От: admin
Дата:
Сообщение: php + postgresql
Следующее
От: "M. François Benoît-Marand"
Дата:
Сообщение: C function working with input/ouput tables failed !