Search Postgresql Archives

Re: problem with serial

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Apr 20, 2012 at 1:20 AM, Adrian Klaver <adrian.klaver@xxxxxxxxx> wrote:
> Am CCing list so more eyes can see this and because I don't use PHP.
>
> On 04/19/2012 07:59 AM, Yvon Thoraval wrote:
>> Fatal error: Call to a member function fetch() on a non-object in
>> /home/yt/Sites/landp_public/landp.php on line 500
>>
>> This is PHP/PDO error message, here is my code :
>> $max_rowid=-1;
>> $sql="SELECT MAX(rowid) FROM items;";
>> $ret=$db->query($sql);
>> while($row=$ret->fetch()){
>> $max_rowid=$row['max'];
>> }

Side point: This is a rather clunky way of handling single-row
results. There's really no need to have a loop like this when you know
the query can't return more than one row - and can't return less than
one row, either (it might return NULL, but it will always have one
row).

The error you're seeing is a cascaded one stemming from $db->query()
returning something that you can't fetch from - off-hand, I'm thinking
it returns either False or Null, but I haven't checked the docs. More
than likely, it's an SQL error in the statement immediately above line
500:

$sql="INSERT INTO items (ctime, [...], infos) VALUES (
'".$dat."', [...], '".str2sql(quoteAsAre($_GET["infos"]))."') RETURNING
rowid;";

Try echoing this statement, then copying and pasting it to
command-line Postgres. Also, get a display of the actual error
returned (I don't have my PHP docs handy to see how that is, but it'll
be $db->last_error or somesuch).

Are you able to switch to using a parameterized query instead of all
this fiddly quoting and escaping? It's a LOT safer and easier.
Possibly you have an issue with the escaping and that's why you
occasionally get SQL errors. What are str2sql() and quoteAsAre()
doing?

ChrisA

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux