note 90336 modified in function.pg-last-oid by danbrown

From: Date: Thu, 16 Apr 2009 20:42:10 +0000
Subject: note 90336 modified in function.pg-last-oid by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153408@lists.php.net to get a copy of this message
Hi, I solved this problem make a function that returns my last inserted id: <?php 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 =) --was-- 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 =) http://php.net/manual/en/function.pg-last-oid.php

« previous php.notes (#153408) next »