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


PHP db2_primary_keys函数代码示例

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


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

示例1: __construct

 /**
  * Constructor for simpledb Proxy
  * Use the values from the configuration file provided to create a PDO for the database
  * Query the database to obtain column metadata and primary key
  *
  * @param string $target                     Target
  * @param string $immediate_caller_directory Directory
  * @param string $binding_config             Config
  */
 public function __construct($target, $immediate_caller_directory, $binding_config)
 {
     SCA::$logger->log('Entering constructor');
     try {
         $this->table = $target;
         $this->config = SCA_Helper::mergeBindingIniAndConfig($binding_config, $immediate_caller_directory);
         if (array_key_exists('username', $this->config)) {
             $username = $this->config['username'];
         } else {
             $username = null;
         }
         if (array_key_exists('password', $this->config)) {
             $password = $this->config['password'];
         } else {
             $password = null;
         }
         if (array_key_exists('namespace', $this->config)) {
             $this->namespace = $this->config['namespace'];
         }
         if (array_key_exists('case', $this->config)) {
             $this->case = $this->config['case'];
         } else {
             $this->case = 'lower';
         }
         if (!array_key_exists('dsn', $this->config)) {
             throw new SCA_RuntimeException("Data source name should be specified");
         }
         $tableName = $this->table;
         // Special processing for IBM databases:
         // IBM table names can contain schema name as prefix
         // Column metadata returned by pdo_ibm does not specify the primary key
         // Hence primary key for IBM databases has to be obtained using
         // db2_primary_key.
         if (strpos($this->config["dsn"], "ibm:") === 0 || strpos($this->config["dsn"], "IBM:") === 0) {
             $this->isIBM = true;
             // Table could be of format schemaName.tableName
             $schemaName = null;
             if (($pos = strrpos($tableName, '.')) !== false) {
                 $schemaName = substr($tableName, 0, $pos);
                 $tableName = substr($tableName, $pos + 1);
             }
             // DSN for IBM databases can be a database name or a connection string
             // Both can be passed onto db2_connect. Remove the dsn prefix if specified
             $database = substr($this->config["dsn"], 4);
             if (strpos($database, "dsn=") === 0 || strpos($database, "DSN=") === 0) {
                 $database = substr($database, 4);
             }
             // Need to make sure the name is in DB2 uppercase style
             $db2TableName = strtoupper($tableName);
             $conn = db2_connect($database, $username, $password);
             $stmt = db2_primary_keys($conn, null, $schemaName, $db2TableName);
             $keys = db2_fetch_array($stmt);
             if (count($keys) > 3) {
                 $this->primary_key = $keys[3];
             } else {
                 throw new SCA_RuntimeException("Table '{$tableName}' does not appear to have a primary key.");
             }
         }
         $this->table_name = $this->_getName($tableName);
         if ($username != null) {
             $this->pdo = new PDO($this->config["dsn"], $username, $password, $this->config);
         } else {
             $this->pdo = new PDO($this->config["dsn"]);
         }
         $this->pdo_driver = $this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME);
         $stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table);
         if (!$stmt->execute()) {
             throw new SCA_RuntimeException(self::_getPDOError($stmt, "select"));
         }
         $columns = array();
         for ($i = 0; $i < $stmt->columnCount(); $i++) {
             $meta = $stmt->getColumnMeta($i);
             $name = $this->_getName($meta["name"]);
             if (in_array("primary_key", $meta["flags"], true)) {
                 $this->primary_key = $name;
             }
             $columns[] = $name;
         }
         //$pk = $this->_getName($this->primary_key);
         SCA::$logger->log("Table {$tableName} PrimaryKey {$this->primary_key}");
         /*
         $metadata = array(
         'name' => $this->table_name,
         'columns' => $columns,
         'PK' => $pk
         );
         */
         $this->datafactory = SDO_DAS_DataFactory::getDataFactory();
         // Define the model on the data factory (from the database)
         $this->datafactory->addType(SCA_Bindings_simpledb_Proxy::ROOT_NS, SCA_Bindings_simpledb_Proxy::ROOT_TYPE);
         $this->datafactory->addType($this->namespace, $this->table_name);
//.........这里部分代码省略.........
开发者ID:psagi,项目名称:sdo,代码行数:101,代码来源:Proxy.php

示例2: strtoupper

 function &MetaColumns($table)
 {
     global $ADODB_FETCH_MODE;
     $false = false;
     if ($this->uCaseTables) {
         $table = strtoupper($table);
     }
     $schema = '';
     $this->_findschema($table, $schema);
     $savem = $ADODB_FETCH_MODE;
     $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
     $colname = "%";
     $qid = db2_columns($this->_connectionID, "", $schema, $table, $colname);
     if (empty($qid)) {
         return $false;
     }
     $rs =& new ADORecordSet_db2($qid);
     $ADODB_FETCH_MODE = $savem;
     if (!$rs) {
         return $false;
     }
     $rs->_fetch();
     $retarr = array();
     /*
     $rs->fields indices
     0 TABLE_QUALIFIER
     1 TABLE_SCHEM
     2 TABLE_NAME
     3 COLUMN_NAME
     4 DATA_TYPE
     5 TYPE_NAME
     6 PRECISION
     7 LENGTH
     8 SCALE
     9 RADIX
     10 NULLABLE
     11 REMARKS
     */
     while (!$rs->EOF) {
         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
             $fld = new ADOFieldObject();
             $fld->name = $rs->fields[3];
             $fld->type = $this->DB2Types($rs->fields[4]);
             // ref: http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraccgen/html/msdn_odk.asp
             // access uses precision to store length for char/varchar
             if ($fld->type == 'C' or $fld->type == 'X') {
                 if ($rs->fields[4] <= -95) {
                     // UNICODE
                     $fld->max_length = $rs->fields[7] / 2;
                 } else {
                     $fld->max_length = $rs->fields[7];
                 }
             } else {
                 $fld->max_length = $rs->fields[7];
             }
             $fld->not_null = !empty($rs->fields[10]);
             $fld->scale = $rs->fields[8];
             $fld->primary_key = false;
             $retarr[strtoupper($fld->name)] = $fld;
         } else {
             if (sizeof($retarr) > 0) {
                 break;
             }
         }
         $rs->MoveNext();
     }
     $rs->Close();
     if (empty($retarr)) {
         $retarr = false;
     }
     $qid = db2_primary_keys($this->_connectionID, "", $schema, $table);
     if (empty($qid)) {
         return $false;
     }
     $rs =& new ADORecordSet_db2($qid);
     $ADODB_FETCH_MODE = $savem;
     if (!$rs) {
         return $retarr;
     }
     $rs->_fetch();
     /*
     $rs->fields indices
     0 TABLE_CAT
     1 TABLE_SCHEM
     2 TABLE_NAME
     3 COLUMN_NAME
     4 KEY_SEQ
     5 PK_NAME
     */
     while (!$rs->EOF) {
         if (strtoupper(trim($rs->fields[2])) == $table && (!$schema || strtoupper($rs->fields[1]) == $schema)) {
             $retarr[strtoupper($rs->fields[3])]->primary_key = true;
         } else {
             if (sizeof($retarr) > 0) {
                 break;
             }
         }
         $rs->MoveNext();
     }
     $rs->Close();
//.........这里部分代码省略.........
开发者ID:rowlandm,项目名称:uiexperiment,代码行数:101,代码来源:adodb-db2.inc.php

示例3: removeNullPrimaryKeys

 /**
  * Given a table name and a hash of columns with values
  * Removes primary key columns from the hash where the value is NULL
  * 
  * @param $table String: name of the table
  * @param $args Array of hashes of column names with values
  * @return Array: tuple containing filtered array of columns, array of primary keys
  */
 private function removeNullPrimaryKeys($table, $args)
 {
     $schema = $this->mSchema;
     // find out the primary keys
     $keyres = db2_primary_keys($this->mConn, null, strtoupper($schema), strtoupper($table));
     $keys = array();
     for ($row = $this->fetchObject($keyres); $row != null; $row = $this->fetchRow($keyres)) {
         $keys[] = strtolower($row->column_name);
     }
     // remove primary keys
     foreach ($args as $ai => $row) {
         foreach ($keys as $ki => $key) {
             if ($row[$key] == null) {
                 unset($row[$key]);
             }
         }
         $args[$ai] = $row;
     }
     // return modified hash
     return array($args, $keys);
 }
开发者ID:rocLv,项目名称:conference,代码行数:29,代码来源:DatabaseIbm_db2.php


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