Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

db2_last_insert_id(3) [php man page]

DB2_LAST_INSERT_ID(3)							 1						     DB2_LAST_INSERT_ID(3)

db2_last_insert_id - Returns the auto generated ID of the last insert query that successfully executed on this connection

SYNOPSIS
string db2_last_insert_id (resource $resource) DESCRIPTION
Returns the auto generated ID of the last insert query that successfully executed on this connection. The result of this function is not affected by any of the following: o A single row INSERT statement with a VALUES clause for a table without an identity column. o A multiple row INSERT statement with a VALUES clause. o An INSERT statement with a fullselect. o A ROLLBACK TO SAVEPOINT statement. PARAMETERS
o $resource - A valid connection resource as returned from db2_connect(3) or db2_pconnect(3). The value of this parameter cannot be a state- ment resource or result set resource. RETURN VALUES
Returns the auto generated ID of last insert query that successfully executed on this connection. EXAMPLES
Example #1 A db2_last_insert_id(3) example The following example shows how to return the auto generated ID of last insert query that successfully executed on this connection. <?php $database = "SAMPLE"; $user = "db2inst1"; $password = "ibmdb2"; $conn = db2_connect($database, $user, $password); if($conn) { $createTable = "CREATE TABLE lastInsertID (id integer GENERATED BY DEFAULT AS IDENTITY, name varchar(20))"; $insertTable = "INSERT INTO lastInsertID (name) VALUES ('Temp Name')"; $stmt = @db2_exec($conn, $createTable); /* Checking for single row inserted. */ $stmt = db2_exec($conn, $insertTable); $ret = db2_last_insert_id($conn); if($ret) { echo "Last Insert ID is : " . $ret . " "; } else { echo "No Last insert ID. "; } db2_close($conn); } else { echo "Connection failed."; } ?> The above example will output: Last Insert ID is : 1 PHP Documentation Group DB2_LAST_INSERT_ID(3)

Check Out this Related Man Page

CUBRID_QUERY(3) 							 1							   CUBRID_QUERY(3)

cubrid_query - Send a CUBRID query

SYNOPSIS
resource cubrid_query (string $query, [resource $conn_identifier]) DESCRIPTION
cubrid_query(3) sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified $conn_identifier. PARAMETERS
o $query - An SQL query Data inside the query should be properly escaped. o $conn_identifier - The CUBRID connection. If the connection identifier is not specified, the last connection opened by cubrid_connect(3) is assumed. RETURN VALUES
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, cubrid_query(3) returns a resource on success, or FALSE on error. For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, cubrid_query(3) returns TRUE on success or FALSE on error. The returned result resource should be passed to cubrid_fetch_array(3), and other functions for dealing with result tables, to access the returned data. Use cubrid_num_rows(3) to find out how many rows were returned for a SELECT statement or cubrid_affected_rows(3) to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement. cubrid_query(3) will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query. EXAMPLES
Example #1 Invalid Query The following query is syntactically invalid, so cubrid_query(3) fails and returns FALSE. <?php $conn = cubrid_connect('localhost', 33000, 'demodb'); $result = cubrid_query('SELECT * WHERE 1=1'); if (!$result) { die('Invalid query: ' . cubrid_error()); } ?> Example #2 Valid Query The following query is valid, so cubrid_query(3) returns a resource. <?php // This could be supplied by a user, for example $firstname = 'fred'; $lastname = 'fox'; $conn = cubrid_connect('localhost', 33000, 'demodb'); cubrid_execute($conn,"DROP TABLE if exists friends"); cubrid_execute($conn,"create table friends(firstname varchar,lastname varchar,address char(24),age int)"); cubrid_execute($conn,"insert into friends values('fred','fox','home-1','20')"); cubrid_execute($conn,"insert into friends values('blue','cat','home-2','21')"); // Formulate Query // This is the best way to perform an SQL query // For more examples, see cubrid_real_escape_string() $query = sprintf("SELECT firstname, lastname, address, age FROM friends WHERE firstname='%s' AND lastname='%s'", cubrid_real_escape_string($firstname), cubrid_real_escape_string($lastname)); // Perform Query $result = cubrid_query($query); // Check result // This shows the actual query sent to CUBRID, and the error. Useful for debugging. if (!$result) { $message = 'Invalid query: ' . cubrid_error() . " "; $message .= 'Whole query: ' . $query; die($message); } // Use result // Attempting to print $result won't allow access to information in the resource // One of the cubrid result functions must be used // See also cubrid_result(), cubrid_fetch_array(), cubrid_fetch_row(), etc. while ($row = cubrid_fetch_assoc($result)) { echo $row['firstname']; echo $row['lastname']; echo $row['address']; echo $row['age']; } // Free the resources associated with the result set // This is done automatically at the end of the script cubrid_free_result($result); ?> SEE ALSO
cubrid_connect(3), cubrid_error(3), cubrid_real_escape_string(3), cubrid_result(3), cubrid_fetch_assoc(3), cubrid_unbuffered_query(3). PHP Documentation Group CUBRID_QUERY(3)
Man Page