한국어 Login Register

Versions available for this page: CUBRID 8.3.0  |  CUBRID 8.3.1  |  CUBRID 8.4.0 |  CUBRID 8.4.1  | 

cubrid_insert_id

Description

The cubrid_insert_id() function retrieves the ID generated for the AUTO_INCREMENT columns which is updated by the previous INSERT query. It returns 0 if the previous query does not generate new rows, or FALSE on failure.

Note CUBRID supports AUTO_INCREMENT for more than one column in a table. In most cases, there will be a single AUTO_INCREMENT column in a table. If there are multiple AUTO_INCREMENT columns, the cubrid_insert_id() should not be used even if it will return a value.

Syntax

array cubrid_insert_id ( string $class_name [, resource $conn_identifier] )

  • class_name : The name of the class (table) that was used in the last INSERT statement for which the auto increment values are retrieved.
  • connection_identifier : Connection identifier previously obtained from a call to cubrid_connect()
Return Value
  • Success : A string representing the ID generated for AUTO_INCREMENT column by the previous query
  • If the previous query does not generate new rows : 0
  • Failure : FALSE
Example

<?php

$conn = cubrid_connect("localhost", 33000, "demodb");

 

@cubrid_execute($conn, "DROP TABLE cubrid_test");

cubrid_execute($conn, "CREATE TABLE cubrid_test (d int AUTO_INCREMENT(1, 2), t varchar)");

 

for ($i = 0; $i < 10; $i++) {

    cubrid_execute($conn, "INSERT INTO cubrid_test(t) VALUES('cubrid_test')");

}

 

$id_list = cubrid_insert_id("cubrid_test");

var_dump($id_list);

 

cubrid_disconnect($conn);

?>

 

The above example will output:

 

array(1) {

    ["d"]=>

    int(19)

}