Re: problem with serial

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: Yvon Thoraval <yvon(dot)thoraval(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: problem with serial
Date: 2012-04-19 15:20:04
Message-ID: 4F902D24.3020909@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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:
>

>
>
> What does the error say?
>
> 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'];
> }
> $last_value=-1;
> $sql="SELECT last_value FROM items_rowid_seq;";
> $ret=$db->query($sql);
> while($row=$ret->fetch()){
> $last_value=$row['last_value'];
> }
> if($last_value<$max_rowid){
> $sql="SELECT setval('items_rowid_seq', max(rowid)) FROM items;";
> $ret=$db->query($sql);
> while($row=$ret->fetch()){
> $last_value=$row['setval'];
> }
> if($last_value<$max_rowid){
> // générer une erreur
> }
> }
> $rowid=-1;
> $sql="INSERT INTO items (ctime, [...], infos) VALUES (
> '".$dat."', [...], '".str2sql(quoteAsAre($_GET["infos"]))."') RETURNING
> rowid;";
> $ret=$db->query($sql);
> while($row=$ret->fetch()){ // LINE 500
> $rowid=$row['rowid'];
> }
>
> if i test it, $ret isn't an object.
>
> may be this has nothing to do with psql but rather with PHP/PDO.
>
> It might even be a typo ?
>
> But this works "sometime" ???

> --
> Yvon
>
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yvon Thoraval 2012-04-19 15:21:23 Re: problem with serial
Previous Message Chris Angelico 2012-04-19 15:11:30 Re: problem with serial