pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedfalse No rows returned error
5+ messages / 3 participants
[nested] [flat]
* false No rows returned error
@ 2002-03-23 16:04 Jim Martinez <jjm@bigbigorg.org>
0 siblings, 3 replies; 5+ messages in thread
From: Jim Martinez @ 2002-03-23 16:04 UTC (permalink / raw)
To: pgsql-sql
I am getting a No rows returned error from a php script when there are
rows.
I can cut and paste the sql statement in the error message into psql and
the query returns 17 rows (which is correct). But why doesn't the result
set in php seem to have any rows?
There are no errors in the apache logs and I don't have access to the
posgtres log file.
I'm using postgreSQL 7.1.3, apache 1.3.22, php 4.0.6 running on a 2.4.7-10
linux kernel.
Below is a code snippet (some lines wrapped, sorry).
Thanks in Advance,
Jim
<?
$conn=pg_connect("user=scott");
// make sure I'mconnecting to the correc db
echo "<b>database name:". pg_dbname($conn)."</b></hr>\n";
if (!$conn){
exit(" connection failed: " . __FILE__ . __LINE__ . "error: " .
pg_errormessage($conn) );
}
$sql = "select pin, last_section_completed, comment from demographics";
$res = pg_exec($conn, $sql) || exit ("query failed: ".__FILE__ . __LINE__
."<br> sql is $sql" );
if (!$res){ exit ("post query check failed");}
//
// script dies here (line 36), falling to the exit clause.
// A warning is printed also :
// Warning: Supplied argument is not a valid
// PostgreSQL result resource
// in /home/www/test/php_debug.php on line 36
$rows = pg_numrows($res) || exit ("No rows returned ".__FILE__ ." line:".
__LINE__ . "<br> sql is $sql" ); // line 36
echo "<table>\n";
for($i=0;$i<$rows;$i++){
echo "<tr>\n";
$pin = pg_results($res,$i,'pin');
$section = pg_results($res, $i, 'last_section_completed');
$comment = pg_results($res, $i, 'comment');
$filler = pg_results($res, $i, 'filler');
echo "<td> $pin </td><td> $section </td><td> $comment</td>";
echo "<td> $filler </td>\n";
echo "</tr>\n";
}
echo "</table>";
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: false No rows returned error
@ 2002-03-23 17:13 Tom Lane <tgl@sss.pgh.pa.us>
parent: Jim Martinez <jjm@bigbigorg.org>
2 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2002-03-23 17:13 UTC (permalink / raw)
To: Jim Martinez <jjm@bigbigorg.org>; +Cc: pgsql-sql
Jim Martinez <jjm@bigbigorg.org> writes:
> I am getting a No rows returned error from a php script when there are
> rows.
I don't think so ...
> // script dies here (line 36), falling to the exit clause.
> // A warning is printed also :
> // Warning: Supplied argument is not a valid
> // PostgreSQL result resource
I think that warning is what to pay attention to, and not the fact
that your script falls over when pg_numrows then chooses to return 0.
I don't know enough about PHP to know what you did wrong, but apparently
$res does not contain the kind of object pg_numrows expects. I think
it's a PHP problem, not an SQL issue at all.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: false No rows returned error
@ 2002-03-23 17:35 Dan Langille <dan@langille.org>
parent: Jim Martinez <jjm@bigbigorg.org>
2 siblings, 1 reply; 5+ messages in thread
From: Dan Langille @ 2002-03-23 17:35 UTC (permalink / raw)
To: Jim Martinez <jjm@bigbigorg.org>; +Cc: pgsql-sql
On 23 Mar 2002 at 11:04, Jim Martinez wrote:
> <?
> $conn=pg_connect("user=scott");
>
> // make sure I'mconnecting to the correc db
> echo "<b>database name:". pg_dbname($conn)."</b></hr>\n";
>
> if (!$conn){
> exit(" connection failed: " . __FILE__ . __LINE__ . "error: " .
> pg_errormessage($conn) );
> }
>
> $sql = "select pin, last_section_completed, comment from demographics";
>
> $res = pg_exec($conn, $sql) || exit ("query failed: ".__FILE__ . __LINE__
> ."<br> sql is $sql" );
Change the above to this, just to be sure:
res = pg_exec($conn, $sql);
if (!$result) {
echo "query failed: ".__FILE__ . __LINE__ ."<br> sql is $sql" );
exit;
}
> if (!$res){ exit ("post query check failed");}
BTW: the above if isn't necessary given the above.
>
> //
> // script dies here (line 36), falling to the exit clause.
> // A warning is printed also :
> // Warning: Supplied argument is not a valid
> // PostgreSQL result resource
> // in /home/www/test/php_debug.php on line 36
Listen to this error.
> $rows = pg_numrows($res) || exit ("No rows returned ".__FILE__ ." line:".
> __LINE__ . "<br> sql is $sql" ); // line 36
--
Dan Langille
The FreeBSD Diary - http://freebsddiary.org/ - practical examples
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: false No rows returned error
@ 2002-03-23 17:38 Dan Langille <dan@langille.org>
parent: Jim Martinez <jjm@bigbigorg.org>
2 siblings, 0 replies; 5+ messages in thread
From: Dan Langille @ 2002-03-23 17:38 UTC (permalink / raw)
To: Jim Martinez <jjm@bigbigorg.org>; +Cc: pgsql-sql
On 23 Mar 2002 at 12:35, Dan Langille wrote:
> res = pg_exec($conn, $sql);
> if (!$result) {
Sorry, I copied and pasted from one of my own php pages: That should be
res, not result.
--
Dan Langille
The FreeBSD Diary - http://freebsddiary.org/ - practical examples
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: false No rows returned error
@ 2002-03-23 18:27 Jim Martinez <jjm@bigbigorg.org>
parent: Dan Langille <dan@langille.org>
0 siblings, 0 replies; 5+ messages in thread
From: Jim Martinez @ 2002-03-23 18:27 UTC (permalink / raw)
To: Dan Langille <dan@langille.org>; +Cc: pgsql-sql
On Mar 23, Dan Langille wrote:
> On 23 Mar 2002 at 11:04, Jim Martinez wrote:
>
> >
> > $res = pg_exec($conn, $sql) || exit ("query failed: ".__FILE__ . __LINE__
> > ."<br> sql is $sql" );
>
> Change the above to this, just to be sure:
>
> $res = pg_exec($conn, $sql);
> if (!$res) {
> echo "query failed: ".__FILE__ . __LINE__ ."<br> sql is $sql" );
> exit;
> }
That worked! Thanks.
Tom, you were right it was a php issue. This morning I subscribed to the
pgsql-php list, then accidentally posted to the sql list that I've been
lurking on.
Best regards,
Jim
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2002-03-23 18:27 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-03-23 16:04 false No rows returned error Jim Martinez <jjm@bigbigorg.org>
2002-03-23 17:13 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-03-23 17:35 ` Dan Langille <dan@langille.org>
2002-03-23 18:27 ` Jim Martinez <jjm@bigbigorg.org>
2002-03-23 17:38 ` Dan Langille <dan@langille.org>
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