note 90336 added to function.pg-last-oid

From: Date: Thu, 16 Apr 2009 20:29:50 +0000
Subject: note 90336 added to function.pg-last-oid
Groups: php.notes 
Request: Send a blank email to php-notes+get-153407@lists.php.net to get a copy of this message
Hi, I solved this problem make a function that returns my last inserted id: function pg_last_inserted_id($con, $table){ #make the initial query $sql = "SELECT * FROM " . $table; #execute $ret = pg_query($con, $sql); #get the field name $campoId = pg_field_name($ret, 0); #change the query, using currval() $sql = "SELECT currval('".$table."_".$campoId."_seq')"; #exec $retorno =pg_query($con, $sql); if(pg_num_rows($ret)>0){ #array $s_dados = pg_fetch_all($retorno); #vars extract($s_dados[0],EXTR_OVERWRITE); return $currval; } else { #case error, returns false return false; } fun =) ---- Server IP: 92.48.74.199 Probable Submitter: 200.212.156.136 ---- Manual Page -- http://www.php.net/manual/en/function.pg-last-oid.php Edit -- https://master.php.net/note/edit/90336 Del: integrated -- https://master.php.net/note/delete/90336/integrated Del: useless -- https://master.php.net/note/delete/90336/useless Del: bad code -- https://master.php.net/note/delete/90336/bad+code Del: spam -- https://master.php.net/note/delete/90336/spam Del: non-english -- https://master.php.net/note/delete/90336/non-english Del: in docs -- https://master.php.net/note/delete/90336/in+docs Del: other reasons-- https://master.php.net/note/delete/90336 Reject -- https://master.php.net/note/reject/90336 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153407) next »