コード例 #1
0
 /**
  * Binds a parameter to the specified variable name.
  *
  * @param mixed $parameter
  *            Name the parameter, either integer or string.
  * @param mixed $variable
  *            Reference to PHP variable containing the value.
  * @param mixed $type
  *            OPTIONAL Datatype of SQL parameter.
  * @param mixed $length
  *            OPTIONAL Length of SQL parameter.
  * @param mixed $options
  *            OPTIONAL Other options.
  * @return bool
  */
 public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
 {
     if (!is_int($parameter) && !is_string($parameter)) {
         /**
          *
          * @see EhrlichAndreas_Db_Exception
          */
         throw new EhrlichAndreas_Db_Exception('Invalid bind-variable position');
     }
     $position = null;
     if (($intval = (int) $parameter) > 0 && $this->_adapter->supportsParameters('positional')) {
         if ($intval >= 1 || $intval <= count($this->_sqlParam)) {
             $position = $intval;
         }
     } else {
         if ($this->_adapter->supportsParameters('named')) {
             if ($parameter[0] != ':') {
                 $parameter = ':' . $parameter;
             }
             if (in_array($parameter, $this->_sqlParam) !== false) {
                 $position = $parameter;
             }
         }
     }
     if ($position === null) {
         /**
          *
          * @see EhrlichAndreas_Db_Exception
          */
         throw new EhrlichAndreas_Db_Exception("Invalid bind-variable position '{$parameter}'");
     }
     // Finally we are assured that $position is valid
     $this->_bindParam[$position] =& $variable;
     return $this->_bindParam($position, $variable, $type, $length, $options);
 }
コード例 #2
0
 /**
  * Executes the current select object and returns the result
  *
  * @param integer $fetchMode
  *            OPTIONAL
  * @param mixed $bind
  *            An array of data to bind to the placeholders.
  * @return EhrlichAndreas_Pdo_Statement EhrlichAndreas_Db_Statement
  */
 public function query($fetchMode = null, $bind = array())
 {
     if (!empty($bind) && method_exists($this, 'bind')) {
         $this->bind($bind);
     }
     $stmt = $this->_adapter->query($this);
     if ($fetchMode == null) {
         $fetchMode = $this->_adapter->getFetchMode();
     }
     $stmt->setFetchMode($fetchMode);
     return $stmt;
 }
コード例 #3
0
 /**
  * Updates table rows with specified data based on a WHERE clause.
  *
  * @param mixed $table
  *            The table to update.
  * @param array $bind
  *            Column-value pairs.
  * @param mixed $where
  *            UPDATE WHERE clause(s).
  * @return int The number of affected rows.
  * @throws EhrlichAndreas_Db_Exception
  */
 public function update($table, array $bind, $where = '')
 {
     return $this->adapter->update($table, $bind, $where);
 }
コード例 #4
0
 /**
  * Special handling for PDO query().
  * All bind parameter names must begin with ':'
  *
  * @param string|EhrlichAndreas_Db_Select|Zend_Db_Select $sql
  *            The SQL statement with placeholders.
  * @param array $bind
  *            An array of data to bind to the placeholders.
  * @return EhrlichAndreas_Db_Adapter_Pdo_Abstract_Statement
  * @throws EhrlichAndreas_Db_Exception To re-throw PDOException.
  */
 public function query($sql, $bind = array())
 {
     if (empty($bind) && is_object($sql) && method_exists($sql, 'getBind')) {
         $bind = $sql->getBind();
     }
     if (is_array($bind)) {
         foreach ($bind as $name => $value) {
             if (!is_int($name) && !preg_match('/^:/', $name)) {
                 $newName = ":{$name}";
                 unset($bind[$name]);
                 $bind[$newName] = $value;
             }
         }
     }
     try {
         return parent::query($sql, $bind);
     } catch (Exception $e) {
         /**
          *
          * @see EhrlichAndreas_Db_Exception
          */
         throw new EhrlichAndreas_Db_Exception($e->getMessage(), $e->getCode(), $e);
     }
 }