当前位置: 首页>>代码示例>>PHP>>正文


PHP db2_last_insert_id函数代码示例

本文整理汇总了PHP中db2_last_insert_id函数的典型用法代码示例。如果您正苦于以下问题:PHP db2_last_insert_id函数的具体用法?PHP db2_last_insert_id怎么用?PHP db2_last_insert_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了db2_last_insert_id函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: insertDb

 /**
  * Inserts a new record into database.
  *
  * @param unknown $sql
  *        	the SQL statement for insert.
  * @throws Exception
  * @return unknown
  */
 public function insertDb($sql)
 {
     $lastId = null;
     $connection = $this->connect();
     $stmt = db2_exec($connection, $sql);
     $lastId = db2_last_insert_id($connection);
     if (!$stmt) {
         $message = "\nCould not insert into database. " . db2_stmt_errormsg();
         throw new Exception($message);
     }
     $this->__destruct();
     return $lastId;
 }
开发者ID:josivansilva,项目名称:php-samples,代码行数:21,代码来源:BaseDAO.php

示例2: get_last_insert_id

 /**
  * This function returns the last insert id.
  *
  * @access public
  * @override
  * @param string $table                         the table to be queried
  * @param string $column                        the column representing the table's id
  * @return integer                              the last insert id
  * @throws Throwable_SQL_Exception              indicates that the query failed
  *
  * @see http://www.php.net/manual/en/function.db2-last-insert-id.php
  */
 public function get_last_insert_id($table = NULL, $column = 'id')
 {
     if (!$this->is_connected()) {
         throw new Throwable_SQL_Exception('Message: Failed to fetch the last insert id. Reason: Unable to find connection.');
     }
     if (is_string($table)) {
         $sql = $this->sql;
         $precompiler = DB_SQL::precompiler($this->data_source);
         $table = $precompiler->prepare_identifier($table);
         $column = $precompiler->prepare_identifier($column);
         $id = (int) $this->query("SELECT MAX({$column}) AS \"id\" FROM {$table};")->get('id', 0);
         $this->sql = $sql;
         return $id;
     } else {
         $id = @db2_last_insert_id($this->resource);
         if ($id === FALSE) {
             throw new Throwable_SQL_Exception('Message: Failed to fetch the last insert id. Reason: :reason', array(':reason' => @db2_conn_error($this->resource)));
         }
         settype($id, 'integer');
         return $id;
     }
 }
开发者ID:ruslankus,项目名称:invoice-crm,代码行数:34,代码来源:Standard.php

示例3: calcInsertId

 /**
  * Updates the mInsertId property with the value of the last insert
  *  into a generated column
  *
  * @param $table      String: sanitized table name
  * @param $primaryKey Mixed: string name of the primary key
  * @param $stmt       Resource: prepared statement resource
  *  of the SELECT primary_key FROM FINAL TABLE ( INSERT ... ) form
  */
 private function calcInsertId($table, $primaryKey, $stmt)
 {
     if ($primaryKey) {
         $this->mInsertId = db2_last_insert_id($this->mConn);
     }
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:15,代码来源:DatabaseIbm_db2.php

示例4: lastInsertId

 function lastInsertId($name = null)
 {
     return db2_last_insert_id($this->_conn);
 }
开发者ID:manish436,项目名称:zform,代码行数:4,代码来源:DB2Connection.php

示例5: getLastGeneratedValue

 /**
  * Get last generated id
  *
  * @param  null $name Ignored
  * @return integer
  */
 public function getLastGeneratedValue($name = null)
 {
     return db2_last_insert_id($this->resource);
 }
开发者ID:totolouis,项目名称:ZF2-Auth,代码行数:10,代码来源:Connection.php

示例6: lastInsertId

 public static function lastInsertId($conn, $table, $IdCol, $dbtype)
 {
     $idCol = db2_last_insert_id($conn);
     return $idCol;
 }
开发者ID:Russell-IO,项目名称:php-syslog-ng,代码行数:5,代码来源:jqGridDb2.php

示例7: execute

 public function execute($bind_params = false)
 {
     $ret_val = false;
     //----------------------------------------------
     // Check Statement Resource
     //----------------------------------------------
     if (!$this->stmt) {
         $this->gen_error('Invalid statement resource.');
         return false;
     }
     //----------------------------------------------
     // Check Bind Parameters
     //----------------------------------------------
     if (!is_array($bind_params)) {
         $this->gen_error('Binding parameters must be passed as an array.');
         return false;
     }
     $this->bind_params = $bind_params;
     //----------------------------------------------
     // Execute Query
     //----------------------------------------------
     $exec_status = @db2_execute($this->stmt, $bind_params);
     //----------------------------------------------
     // Check for Errors
     //----------------------------------------------
     if (!$exec_status) {
         if ($this->check_and_print_stmt_error($this->stmt)) {
             return false;
         }
         $this->gen_error('Prepared query execution failed.');
         return false;
     }
     //----------------------------------------------
     // Create Data Result Object if Necessary
     //----------------------------------------------
     if ($this->stmt && gettype($this->stmt) != 'boolean') {
         //----------------------------------------------
         // Affected Rows
         //----------------------------------------------
         $this->affected_rows = db2_num_rows($this->stmt);
         $ret_val = $this->affected_rows;
         //----------------------------------------------
         // Create Data Result Object
         //----------------------------------------------
         $this->data_result = new data_result($this->stmt, $this->data_src);
         //----------------------------------------------
         // Last Insert ID
         //----------------------------------------------
         $this->last_id = db2_last_insert_id($this->handle);
     }
     //----------------------------------------------
     // Return Data Result Object if it exists
     //----------------------------------------------
     if ($this->data_result) {
         $this->num_rows = $this->data_result->num_rows();
         $this->num_fields = $this->data_result->num_fields();
         $ret_val = $this->data_result;
     }
     //----------------------------------------------
     // Check for Errors
     //----------------------------------------------
     if ($this->check_and_print_stmt_error($this->stmt)) {
         return false;
     }
     return $ret_val;
 }
开发者ID:codifyllc,项目名称:phpopenfw,代码行数:66,代码来源:dt_db2.class.php

示例8: getInsertId

 /**
  * Get last insert id (if available)
  *
  * @return  int
  * 
  * @throws  \Comodojo\Exception\DatabaseException
  */
 public function getInsertId()
 {
     switch ($this->model) {
         case "MYSQLI":
             $return = $this->handler->insert_id;
             break;
         case "MYSQL_PDO":
         case "SQLITE_PDO":
             $return = $this->handler->lastInsertId();
             break;
         case "ORACLE_PDO":
             try {
                 $return = self::oracleLastInsertId($this->handler);
             } catch (DatabaseException $de) {
                 throw $de;
             }
             break;
         case "DBLIB_PDO":
             try {
                 $return = self::dblibLastInsertId($this->handler);
             } catch (DatabaseException $de) {
                 throw $de;
             }
             break;
         case "DB2":
             $return = db2_last_insert_id($this->handler);
             break;
         case "POSTGRESQL":
             //$return = pg_last_oid($this->raw_data);
             $return = self::postgresqlLastInsertId($this->handler);
             break;
     }
     return intval($return);
 }
开发者ID:comodojo,项目名称:database,代码行数:41,代码来源:QueryResult.php

示例9: getInsertedId

 /**	
  * Get the auto generated id used in the last query
  * @return Number
  */
 public function getInsertedId()
 {
     db2_last_insert_id($this->conn);
 }
开发者ID:ryanblanchard,项目名称:Dashboard,代码行数:8,代码来源:DB2Connection.php

示例10: resultsToArray


//.........这里部分代码省略.........
             $this->rows = $data->rowCount();
             break;
         case "ORACLE_PDO":
             if (!is_object($data)) {
                 throw new DatabaseException('Invalid result data for model ' . $this->model);
             }
             switch ($this->fetch) {
                 case 'NUM':
                     $fetch = \PDO::FETCH_NUM;
                     break;
                 case 'ASSOC':
                     $fetch = \PDO::FETCH_ASSOC;
                     break;
                 default:
                     $fetch = \PDO::FETCH_BOTH;
                     break;
             }
             $result = $data->fetchAll($fetch);
             $this->length = sizeof($result);
             $this->rows = $data->rowCount();
             try {
                 $this->id = $this->oracleLastInsertId();
             } catch (DatabaseException $de) {
                 throw $de;
             }
             break;
         case "DBLIB_PDO":
             if (!is_object($data)) {
                 throw new DatabaseException('Invalid result data for model ' . $this->model);
             }
             switch ($this->fetch) {
                 case 'NUM':
                     $fetch = \PDO::FETCH_NUM;
                     break;
                 case 'ASSOC':
                     $fetch = \PDO::FETCH_ASSOC;
                     break;
                 default:
                     $fetch = \PDO::FETCH_BOTH;
                     break;
             }
             $result = $data->fetchAll($fetch);
             $this->length = sizeof($result);
             $this->rows = $data->rowCount();
             try {
                 $this->id = $this->dblibLastInsertId();
             } catch (DatabaseException $de) {
                 throw $de;
             }
             break;
         case "DB2":
             if (!is_resource($data) or @get_resource_type($data) != "DB2 Statement") {
                 throw new DatabaseException('Invalid result data for model ' . $this->model);
             }
             $this->length = db2_num_fields($data);
             $this->id = db2_last_insert_id($this->dbh);
             $this->rows = db2_num_rows($data);
             switch ($this->fetch) {
                 case 'NUM':
                     while ($row = db2_fetch_row($data)) {
                         array_push($result, $row);
                     }
                     break;
                 case 'ASSOC':
                     while ($row = db2_fetch_assoc($data)) {
                         array_push($result, $row);
                     }
                     break;
                 default:
                     while ($row = db2_fetch_both($data)) {
                         array_push($result, $row);
                     }
                     break;
             }
             break;
         case "POSTGRESQL":
             if (!is_resource($data) or @get_resource_type($data) != "pgsql result") {
                 throw new DatabaseException('Invalid result data for model ' . $this->model);
             }
             $this->length = pg_num_rows($data);
             $this->id = pg_last_oid($data);
             $this->rows = pg_affected_rows($data);
             while ($iterator < $this->length) {
                 switch ($this->fetch) {
                     case 'NUM':
                         $result[$iterator] = pg_fetch_array($data);
                         break;
                     case 'ASSOC':
                         $result[$iterator] = pg_fetch_assoc($data);
                         break;
                     default:
                         $result[$iterator] = pg_fetch_all($data);
                         break;
                 }
                 $iterator++;
             }
             break;
     }
     return array("data" => $result, "length" => $this->length, "id" => $this->id, "affected_rows" => $this->rows);
 }
开发者ID:noodless84,项目名称:GestPortal,代码行数:101,代码来源:Database.php


注:本文中的db2_last_insert_id函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。