From: Chris on
Andy Shellam (Mailing Lists) wrote:
> Hi Giff,
>
> No worries - I know the feeling well!
>
> At first glance this looks OK, however I notice that there is no "res"
> property defined in the STH class, like there is session and query.
>
> $this->res on line 202 is what's causing the issue - PHP is saying it's
> not a valid PostgreSQL result resource, so if you trace back to where
> that comes from, you get to line 175:
>
> $this->res = @pg_execute($this->session, $query);
>
> PHP is therefore trying to assign a query result to a property that
> doesn't exist. I would have expected PHP to throw an error at this but
> it may have been obscured with your logging settings, I'm not sure.

Close - the '@' before pg_execute is hiding the notice/warning.

I'd say check your database username/password are correct.

$this->session is probably not a postgres resource.

--
Postgresql & php tutorials
http://www.designmagick.com/

From: andy-lists on
Hi Chris,

>>
>> $this->res = @pg_execute($this->session, $query);
>> PHP is therefore trying to assign a query result to a property that
>> doesn't exist. I would have expected PHP to throw an error at this
>> but it may have been obscured with your logging settings, I'm not
>> sure.
>
> Close - the '@' before pg_execute is hiding the notice/warning.
>
> I'd say check your database username/password are correct.

Yeah I noticed that, but the line below it does a check to see if the
pg_execute command succeeded, and if it didn't it kills the script,
but that's not happening - it's getting further down the line, which
is why I think $this->res is not being persisted across method calls.

Andy
From: Giff Hammar on
Andy,

Thanks for your help! The var_dump after the pg_execute showed that the
execute() method wasn't being called (I left a line out of the calling
script). Once I fixed that, I changed pg_execute back to pg_exec and it
worked as expected. Now I have to figure out the difference between
pg_exec and pg_execute... From what I can tell, pg_exec isn't supported
any more and I should be using pg_execute instead... Thanks again.

Giff

On Tue, 2009-10-27 at 19:51 +0000, Andy Shellam (Mailing Lists) wrote:
> Hi Giff,
>
> No worries - I know the feeling well!
>
> At first glance this looks OK, however I notice that there is no "res"
> property defined in the STH class, like there is session and query.
>
> $this->res on line 202 is what's causing the issue - PHP is saying
> it's not a valid PostgreSQL result resource, so if you trace back to
> where that comes from, you get to line 175:
>
> $this->res = @pg_execute($this->session, $query);
>
> PHP is therefore trying to assign a query result to a property that
> doesn't exist. I would have expected PHP to throw an error at this
> but it may have been obscured with your logging settings, I'm not sure.
>
> Try adding "public $res;" after line 85 and see what you get. You
> could also add "var_dump($this->res);" between lines 175 and 176 which
> should tell you what PHP thinks "$this->res" is.
>
> And lastly, you could get a back-trace of the rows() method call to
> see if it's being called before $this->res has been assigned - just
> add the line "var_dump(debug_backtrace());" between lines 201 and 202.
>
> Hope this gives you a starting pointer!
>
> Regards,
> Andy
>
> On 27 October2009, at 19:36, Giff Hammar wrote:
>
> > Andy,
> >
> > Sometimes I'm too fast for my own good. I added .txt to the file and
> > it
> > should be visible as http://www.sv-phoenix.com/dbi_pgsql.txt. Just
> > appending the .txt didn't work.
> >
> > Thanks for taking a look!
> >
> > Giff
> >
> > On Tue, 2009-10-27 at 17:49 +0000, Andy Shellam (Mailing Lists) wrote:
> >> Hi Giff,
> >>
> >> I want to have a look at this for you, but you'll need to put the
> >> file
> >> on your server as plain-text because your server is parsing the PHP
> >> code and only sending us the output, not the source code.
> >>
> >> Append *.txt to your file on the server and we should be able to see
> >> it better!
> >>
> >> Andy
> >>
> >> On 27 October2009, at 12:48, Giff Hammar wrote:
> >>
> >>> I started having trouble with a DBI interface to my PostgreSQL
> >>> database
> >>> after I built a new Ubuntu machine. The Postgres version is 8.3 and
> >>> the
> >>> DBI was written several years ago (by someone else). I'm using PHP
> >>> version 5.2.6-3ubuntu4.2 with apache2. The problem is that I get the
> >>> error:
> >>>
> >>> Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL
> >>> result resource in /var/www/lib/dbi_pgsql.php on line 202
> >>>
> >>> I don't know what to check next to figure out why this is happening.
> >>> Here is what I have done so far:
> >>>
> >>> - Updated the old PHP commands in the dbi file to reflect new ones
> >>> var -> public
> >>> pg_numrows -> pg_num_rows
> >>> pg_cmdtuples -> pg_affected_rows
> >>> pg_exec -> pg_execute
> >>> - Connected to the database as the same user by using straight PHP
> >>> calls
> >>> vs the DBI. It worked fine.
> >>> - Connected to the database via psql and that worked fine, too.
> >>>
> >>> There is something with the DBI class that is not right, but I am a
> >>> novice with objects and classes, so I can't pin it down. The whole
> >>> file
> >>> is here: http://www.sv-phoenix.com/dbi_pgsql.php - it's 205 lines
> >>> so I
> >>> didn't want to put the whole thing in this post.
> >>>
> >>> If anyone can take a look at it and let me know what to check
> >>> next, I
> >>> would really appreciate it.
> >>>
> >>> Giff
> >>>
> >>>
> >>> --
> >>> PHP Database Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>>
> >>
> >>
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>

From: andy-lists on
Hi Giff,

Glad you got it sorted!

pg_exec() is the old (and deprecated) name for pg_query - this behaves
differently to pg_execute.

pg_execute runs a SQL statement that has previously been prepared with
a call to pg_prepare, while pg_query runs a SQL query directly.

http://www.php.net/manual/en/function.pg-prepare.php
http://www.php.net/manual/en/function.pg-query.php

After a quick glance through your code, I think pg_query is what you
want.

HTH,

Andy

On 27 October2009, at 22:06, Giff Hammar wrote:

> Andy,
>
> Thanks for your help! The var_dump after the pg_execute showed that
> the
> execute() method wasn't being called (I left a line out of the calling
> script). Once I fixed that, I changed pg_execute back to pg_exec and
> it
> worked as expected. Now I have to figure out the difference between
> pg_exec and pg_execute... From what I can tell, pg_exec isn't
> supported
> any more and I should be using pg_execute instead... Thanks again.
>
> Giff
>
> On Tue, 2009-10-27 at 19:51 +0000, Andy Shellam (Mailing Lists) wrote:
>> Hi Giff,
>>
>> No worries - I know the feeling well!
>>
>> At first glance this looks OK, however I notice that there is no
>> "res"
>> property defined in the STH class, like there is session and query.
>>
>> $this->res on line 202 is what's causing the issue - PHP is saying
>> it's not a valid PostgreSQL result resource, so if you trace back to
>> where that comes from, you get to line 175:
>>
>> $this->res = @pg_execute($this->session, $query);
>>
>> PHP is therefore trying to assign a query result to a property that
>> doesn't exist. I would have expected PHP to throw an error at this
>> but it may have been obscured with your logging settings, I'm not
>> sure.
>>
>> Try adding "public $res;" after line 85 and see what you get. You
>> could also add "var_dump($this->res);" between lines 175 and 176
>> which
>> should tell you what PHP thinks "$this->res" is.
>>
>> And lastly, you could get a back-trace of the rows() method call to
>> see if it's being called before $this->res has been assigned - just
>> add the line "var_dump(debug_backtrace());" between lines 201 and
>> 202.
>>
>> Hope this gives you a starting pointer!
>>
>> Regards,
>> Andy
>>
>> On 27 October2009, at 19:36, Giff Hammar wrote:
>>
>>> Andy,
>>>
>>> Sometimes I'm too fast for my own good. I added .txt to the file and
>>> it
>>> should be visible as http://www.sv-phoenix.com/dbi_pgsql.txt. Just
>>> appending the .txt didn't work.
>>>
>>> Thanks for taking a look!
>>>
>>> Giff
>>>
>>> On Tue, 2009-10-27 at 17:49 +0000, Andy Shellam (Mailing Lists)
>>> wrote:
>>>> Hi Giff,
>>>>
>>>> I want to have a look at this for you, but you'll need to put the
>>>> file
>>>> on your server as plain-text because your server is parsing the PHP
>>>> code and only sending us the output, not the source code.
>>>>
>>>> Append *.txt to your file on the server and we should be able to
>>>> see
>>>> it better!
>>>>
>>>> Andy
>>>>
>>>> On 27 October2009, at 12:48, Giff Hammar wrote:
>>>>
>>>>> I started having trouble with a DBI interface to my PostgreSQL
>>>>> database
>>>>> after I built a new Ubuntu machine. The Postgres version is 8.3
>>>>> and
>>>>> the
>>>>> DBI was written several years ago (by someone else). I'm using PHP
>>>>> version 5.2.6-3ubuntu4.2 with apache2. The problem is that I get
>>>>> the
>>>>> error:
>>>>>
>>>>> Warning: pg_num_rows(): supplied argument is not a valid
>>>>> PostgreSQL
>>>>> result resource in /var/www/lib/dbi_pgsql.php on line 202
>>>>>
>>>>> I don't know what to check next to figure out why this is
>>>>> happening.
>>>>> Here is what I have done so far:
>>>>>
>>>>> - Updated the old PHP commands in the dbi file to reflect new ones
>>>>> var -> public
>>>>> pg_numrows -> pg_num_rows
>>>>> pg_cmdtuples -> pg_affected_rows
>>>>> pg_exec -> pg_execute
>>>>> - Connected to the database as the same user by using straight PHP
>>>>> calls
>>>>> vs the DBI. It worked fine.
>>>>> - Connected to the database via psql and that worked fine, too.
>>>>>
>>>>> There is something with the DBI class that is not right, but I
>>>>> am a
>>>>> novice with objects and classes, so I can't pin it down. The whole
>>>>> file
>>>>> is here: http://www.sv-phoenix.com/dbi_pgsql.php - it's 205 lines
>>>>> so I
>>>>> didn't want to put the whole thing in this post.
>>>>>
>>>>> If anyone can take a look at it and let me know what to check
>>>>> next, I
>>>>> would really appreciate it.
>>>>>
>>>>> Giff
>>>>>
>>>>>
>>>>> --
>>>>> PHP Database Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> PHP Database Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

From: Samuel ROZE on
Why not using PDO ? It is a global and standardized method to access
to data. :-)

2009/10/27 Giff Hammar <ghammar(a)sv-phoenix.com>:
> I started having trouble with a DBI interface to my PostgreSQL database
> after I built a new Ubuntu machine. The Postgres version is 8.3 and the
> DBI was written several years ago (by someone else). I'm using PHP
> version 5.2.6-3ubuntu4.2 with apache2. The problem is that I get the
> error:
>
> Warning: pg_num_rows(): supplied argument is not a valid PostgreSQL
> result resource in /var/www/lib/dbi_pgsql.php on line 202
>
> I don't know what to check next to figure out why this is happening.
> Here is what I have done so far:
>
> - Updated the old PHP commands in the dbi file to reflect new ones
>    var -> public
>    pg_numrows -> pg_num_rows
>    pg_cmdtuples -> pg_affected_rows
>    pg_exec -> pg_execute
> - Connected to the database as the same user by using straight PHP calls
>  vs the DBI. It worked fine.
> - Connected to the database via psql and that worked fine, too.
>
> There is something with the DBI class that is not right, but I am a
> novice with objects and classes, so I can't pin it down. The whole file
> is here: http://www.sv-phoenix.com/dbi_pgsql.php - it's 205 lines so I
> didn't want to put the whole thing in this post.
>
> If anyone can take a look at it and let me know what to check next, I
> would really appreciate it.
>
> Giff
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>