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


PHP Connection::prepareStatement方法代码示例

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


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

示例1: prepareStatement

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

示例2: sessionWrite

 /**
  * Write session data.
  *
  * @param string A session ID.
  * @param string A serialized chunk of session data.
  *
  * @return bool true, if the session was written, otherwise an exception is
  *              thrown.
  *
  * @throws <b>DatabaseException</b> If the session data cannot be written.
  */
 public function sessionWrite($id, $data)
 {
     // get table/column
     $db_table = $this->getParameterHolder()->get('db_table');
     $db_data_col = $this->getParameterHolder()->get('db_data_col', 'sess_data');
     $db_id_col = $this->getParameterHolder()->get('db_id_col', 'sess_id');
     $db_time_col = $this->getParameterHolder()->get('db_time_col', 'sess_time');
     $sql = 'UPDATE ' . $db_table . ' SET ' . $db_data_col . '=?, ' . $db_time_col . ' = ' . time() . ' WHERE ' . $db_id_col . '=?';
     try {
         $stmt = $this->db->prepareStatement($sql);
         $stmt->setString(1, $data);
         $stmt->setString(2, $id);
         $stmt->executeUpdate();
         return true;
     } catch (SQLException $e) {
         $error = 'Creole SQLException was thrown when trying to manipulate session data. ';
         $error .= 'Message: ' . $e->getMessage();
         throw new sfDatabaseException($error);
     }
     return false;
 }
开发者ID:taryono,项目名称:school,代码行数:32,代码来源:sfCreoleSessionStorage.class.php

示例3: doSelect

 /**
  * Method to do selects.
  *
  * @param Criteria $criteria The Criteria object used to build the SELECT statement.
  * @param Connection $con
  * @return array Array of selected Objects
  * @throws PropelException Any exceptions caught during processing will be
  * rethrown wrapped into a PropelException.
  */
 public static function doSelect(Criteria $criteria, $tableName, $con = null)
 {
     $dbMap = Propel::getDatabaseMap($criteria->getDbName());
     $stmt = null;
     try {
         $params = array();
         $sql = self::createSelectSql($criteria, $tableName, $params);
         $sql['params'] = $params;
         $stmt = $con->prepareStatement($sql);
         //$stmt->setLimit($criteria->getLimit());
         $sql['limit'] = $criteria->getLimit();
         //$stmt->setOffset($criteria->getOffset());
         $sql['offset'] = $criteria->getOffset();
         //$rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
         $rs = $con->executeQuery($sql, ResultSet::FETCHMODE_NUM);
     } catch (Exception $e) {
         if ($stmt) {
             $stmt->close();
         }
         throw new PropelException($e);
     }
     return $rs;
 }
开发者ID:emildev35,项目名称:processmaker,代码行数:32,代码来源:class.ArrayPeer.php

示例4: doUpdate

 /**
  * Method used to update rows in the DB.  Rows are selected based
  * on selectCriteria and updated using values in updateValues.
  * <p>
  * Use this method for performing an update of the kind:
  * <p>
  * WHERE some_column = some value AND could_have_another_column =
  * another value AND so on.
  *
  * @param $selectCriteria A Criteria object containing values used in where
  *		clause.
  * @param $updateValues A Criteria object containing values used in set
  *		clause.
  * @param $con 	The Connection to use.
  * @return int	The number of rows affected by last update statement.  For most
  * 				uses there is only one update statement executed, so this number
  * 				will correspond to the number of rows affected by the call to this
  * 				method.  Note that the return value does require that this information
  * 				is returned (supported) by the Creole db driver.
  * @throws PropelException
  */
 public static function doUpdate(Criteria $selectCriteria, Criteria $updateValues, Connection $con)
 {
     $db = Propel::getDB($selectCriteria->getDbName());
     $dbMap = Propel::getDatabaseMap($selectCriteria->getDbName());
     // Get list of required tables, containing all columns
     $tablesColumns = $selectCriteria->getTablesColumns();
     // we also need the columns for the update SQL
     $updateTablesColumns = $updateValues->getTablesColumns();
     $affectedRows = 0;
     // initialize this in case the next loop has no iterations.
     foreach ($tablesColumns as $tableName => $columns) {
         $whereClause = array();
         $selectParams = array();
         foreach ($columns as $colName) {
             $sb = "";
             $selectCriteria->getCriterion($colName)->appendPsTo($sb, $selectParams);
             $whereClause[] = $sb;
         }
         $rs = null;
         $stmt = null;
         try {
             $sqlSnippet = implode(" AND ", $whereClause);
             if ($selectCriteria->isSingleRecord()) {
                 // Get affected records.
                 $sql = "SELECT COUNT(*) FROM " . $tableName . " WHERE " . $sqlSnippet;
                 $stmt = $con->prepareStatement($sql);
                 self::populateStmtValues($stmt, $selectParams, $dbMap);
                 $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
                 $rs->next();
                 if ($rs->getInt(1) > 1) {
                     $rs->close();
                     throw new PropelException("Expected to update 1 record, multiple matched.");
                 }
                 $rs->close();
             }
             $sql = "UPDATE " . $tableName . " SET ";
             foreach ($updateTablesColumns[$tableName] as $col) {
                 $sql .= substr($col, strpos($col, '.') + 1) . " = ?,";
             }
             $sql = substr($sql, 0, -1) . " WHERE " . $sqlSnippet;
             Propel::log($sql, Propel::LOG_DEBUG);
             $stmt = $con->prepareStatement($sql);
             // Replace '?' with the actual values
             self::populateStmtValues($stmt, array_merge(self::buildParams($updateTablesColumns[$tableName], $updateValues), $selectParams), $dbMap);
             $affectedRows = $stmt->executeUpdate();
             $stmt->close();
         } catch (Exception $e) {
             if ($rs) {
                 $rs->close();
             }
             if ($stmt) {
                 $stmt->close();
             }
             Propel::log($e->getMessage(), Propel::LOG_ERR);
             throw new PropelException("Unable to execute UPDATE statement.", $e);
         }
     }
     // foreach table in the criteria
     return $affectedRows;
 }
开发者ID:rodrigoprestesmachado,项目名称:whiteboard,代码行数:81,代码来源:BasePeer.php

示例5: doInsert

 /**
  * Saves the data in this Record to the database with an INSERT statement
  * @return int
  * @throws DataSetException, SQLException
  */
 private function doInsert(Connection $conn = null)
 {
     $stmt = null;
     try {
         $stmt = $conn->prepareStatement($this->getInsertSql());
         $ps = 1;
         foreach ($this->dirtyColumns() as $col) {
             $val = $this->getValue($col);
             $setter = 'set' . CreoleTypes::getAffix($table->getColumn($col)->getType());
             $stmt->{$setter}($ps++, $val);
         }
         $ret = $stmt->executeUpdate();
         if ($this->ds->refreshOnSave()) {
             $this->refresh();
         } else {
             // Marks all of the values clean since they have now been saved
             $this->markRecordClean();
         }
         $this->setSaveType(Record::AFTERINSERT);
         if ($ret > 1) {
             // a little late again...
             throw new SQLException("There were " . $ret . " rows inserted with this records key value.");
         }
         return $ret;
     } catch (SQLException $e) {
         if ($stmt) {
             $stmt->close();
         }
         throw $e;
     }
 }
开发者ID:nmicht,项目名称:tlalokes-in-acst,代码行数:36,代码来源:Record.php


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