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


PHP Connection::createStatement方法代码示例

本文整理汇总了PHP中Connection::createStatement方法的典型用法代码示例。如果您正苦于以下问题:PHP Connection::createStatement方法的具体用法?PHP Connection::createStatement怎么用?PHP Connection::createStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Connection的用法示例。


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

示例1: getAssoc

 /**
  * Fetch the entire result set of a query and return it as an
  * associative array using the first column as the key.
  * 
  * Note: column names are not preserved when using this function.
  * 
  * <code>
  * For example, if the table 'mytable' contains:
  *
  *   ID      TEXT       DATE
  * --------------------------------
  *   1       'one'      944679408
  *   2       'two'      944679408
  *   3       'three'    944679408
  *
  * $q = new Query("SELECT id, text FROM mytable") 
  * $q->getAssoc() returns:
  *    array(
  *      '1' => array('one'),
  *      '2' => array('two'),
  *      '3' => array('three'),
  *    )
  * 
  * ... or call $q->getAssoc($scalar=true) to avoid wrapping results in an array (only
  * applies if only 2 cols are returned):
  *  array(
  *      '1' => 'one',
  *      '2' => 'two',
  *      '3' => 'three',
  *    )
  * </code>
  * Keep in mind that database functions in PHP usually return string
  * values for results regardless of the database's internal type.
  *
  * @param boolean $scalar Used only when the query returns
  * exactly two columns.  If TRUE, the values of second column are not
  * wrapped in an array.  Default here is false, in order to assure expected
  * behavior.
  * 
  * @return array Associative array with results from the query.
  * @author Lukas Smith <smith@backendmedia.com> (MDB)
  */
 public function getAssoc($scalar = false)
 {
     $stmt = $this->conn->createStatement();
     if ($this->max) {
         $stmt->setLimit($this->max);
     }
     if ($this->start) {
         $stmt->setOffset($this->start);
     }
     $rs = $stmt->executeQuery($this->sql);
     $numcols = null;
     $results = array();
     while ($rs->next()) {
         $fields = $rs->getRow();
         if ($numcols === null) {
             $numcols = count($fields);
         }
         if (!$scalar || $numcols > 2) {
             $results[array_shift($fields)] = array_values($fields);
         } else {
             $results[array_shift($fields)] = array_shift($fields);
         }
     }
     $rs->close();
     $stmt->close();
     return $results;
 }
开发者ID:BackupTheBerlios,项目名称:php5cms-svn,代码行数:69,代码来源:Query.php

示例2: testExecute

 public function testExecute()
 {
     $exch = DriverTestManager::getExchange('StatementTest.executeUpdate');
     $stmt = $this->conn->createStatement();
     $res = $stmt->execute($exch->getSql());
     $this->assertFalse($res, "Expected resulst of execute() to be FALSE because an update statement was executed (this is to match JDBC return values).");
     $this->assertEquals(1, $stmt->getUpdateCount());
     $exch = DriverTestManager::getExchange('StatementTest.executeQuery');
     $stmt = $this->conn->createStatement();
     $res = $stmt->execute($exch->getSql());
     $this->assertTrue($res, "Expected resulst of execute() to be TRUE because a select query was executed (this is to match JDBC return values).");
     $this->assertTrue($stmt->getResultSet() instanceof ResultSet, "Expected to be able to getResultSet() after call to execute() w/ SELECT query.");
     $stmt->close();
 }
开发者ID:BackupTheBerlios,项目名称:php5cms-svn,代码行数:14,代码来源:StatementTest.php

示例3: unlockTable

 /**
  * Unlocks the specified table.
  *
  * @param      Connection $con The Creole connection to use.
  * @param      string $table The name of the table to unlock.
  * @throws     SQLException No Statement could be created or
  * executed.
  */
 public function unlockTable(Connection $con, $table)
 {
     $statement = $con->createStatement();
     $statement->executeUpdate("UNLOCK TABLES");
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:13,代码来源:DBMySQL.php

示例4: lockTable

 /**
  * Locks the specified table.
  *
  * @param      Connection $con The Creole connection to use.
  * @param      string $table The name of the table to lock.
  * @throws     SQLException No Statement could be created or executed.
  */
 public function lockTable(Connection $con, $table)
 {
     $statement = $con->createStatement();
     $sql = "SELECT next_id FROM " . $table . " FOR UPDATE";
     $statement->executeQuery($sql);
 }
开发者ID:Daniel-Marynicz,项目名称:symfony1-legacy,代码行数:13,代码来源:DBSybase.php

示例5: createStatement

 /**
  * @see Connection::createStatement()
  */
 public function createStatement()
 {
     $obj = $this->childConnection->createStatement();
     $objClass = get_class($obj);
     return new $objClass($this);
 }
开发者ID:rodrigoprestesmachado,项目名称:whiteboard,代码行数:9,代码来源:DebugConnection.php

示例6: createStatement

 /**
  * @see Connection::createStatement()
  */
 public function createStatement()
 {
     return new DBArrayPreparedStatement($this, null);
     return new DBArrayPreparedStatement($this, $dataSql['sql']);
     krumo('DBArrayConnection createStatement ');
     die;
     $obj = $this->childConnection->createStatement();
     $objClass = get_class($obj);
     return new $objClass($this);
 }
开发者ID:emildev35,项目名称:processmaker,代码行数:13,代码来源:DBArrayConnection.php

示例7: runStatements

 /**
  * Executes the passed SQL statements.
  */
 protected static function runStatements($statements, Connection $conn)
 {
     $stmt = $conn->createStatement();
     foreach ($statements as $sql) {
         // print "Executing : $sql \n";
         try {
             $stmt->execute($sql);
         } catch (Exception $e) {
             if (!stripos($e->getMessage(), "drop table")) {
                 print "Error executing SQL: " . $sql . "\n";
                 print $e->getMessage() . "\n";
                 print "=== Attempting to continue === \n";
             }
         }
     }
 }
开发者ID:BackupTheBerlios,项目名称:php5cms-svn,代码行数:19,代码来源:DriverTestManager.php


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