note 83084 added to function.pg-last-oid
| From: | malyszg at o2 dot pl | Date: | Fri, 09 May 2008 09:59:02 +0000 |
| Subject: | note 83084 added to function.pg-last-oid | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139210@lists.php.net to get a copy of this message | ||
//function which return last row ID. It works like mysqli_insert_id() function
function pg_insert_id($pg,$query){// $pg - string connection, $query - sql command
$regExp = preg_match_all("/nextval\('([a-zA-Z0-9_]+)'\)/",$query,$array);
$sequence = $array[1][0];
$select = "SELECT currval('$sequence')";
$load = pg_query($pg,$select);
$id = pg_fetch_array($load,null,PGSQL_NUM);
return $id[0];
}
$connect = pg_connect("host dbname user password");
$insert = "Insert into klienci
Values(nextval('autonumerowanie'),'Krzysztof','Nowak')";
$wykonaj = pg_query($connect,$insert);
$lastID = pg_insert_id($connect,$insert);
/*call pg_insert_id function with two arguments.
First argument is a string connection. Second argument is a SQL statement */
echo $lastID;
----
Server IP: 82.160.94.10
Probable Submitter: 83.21.248.173
----
Manual Page -- http://www.php.net/manual/en/function.pg-last-oid.php
Edit -- https://master.php.net/note/edit/83084
Del: integrated -- https://master.php.net/note/delete/83084/integrated
Del: useless -- https://master.php.net/note/delete/83084/useless
Del: bad code -- https://master.php.net/note/delete/83084/bad+code
Del: spam -- https://master.php.net/note/delete/83084/spam
Del: non-english -- https://master.php.net/note/delete/83084/non-english
Del: in docs -- https://master.php.net/note/delete/83084/in+docs
Del: other reasons-- https://master.php.net/note/delete/83084
Reject -- https://master.php.net/note/reject/83084
Search -- https://master.php.net/manage/user-notes.php