Example #1
0
 /**
  * Binds a parameter to the specified variable name.
  *
  * @param string $parameter Parameter identifier. For a prepared statement
  *   using named placeholders, this will be a parameter name of the form
  *   :name. For a prepared statement using question mark placeholders, this
  *   will be the 1-indexed position of the parameter.
  * @param mixed $variable Name of the PHP variable to bind to the SQL
  *   statement parameter.
  * @param int $dataType Explicit data type for the parameter using the
  *   PDO::PARAM_* constants.
  * @param int $maxLength Length of the data type. To indicate that a
  *   parameter is an OUT parameter from a stored procedure, you must
  *   explicitly set the length.
  * @param array $options [optional]
  * @return bool TRUE on success or FALSE on failure.
  * @todo Map PDO datatypes to oci8 datatypes and implement support for
  *   datatypes and length.
  */
 public function bindParam($parameter, &$variable, $dataType = PDO::PARAM_STR, $maxLength = -1, $options = null)
 {
     // strip INOUT type for oci
     $dataType &= ~PDO::PARAM_INPUT_OUTPUT;
     // Replace the first @oci8param to a pseudo named parameter
     if (is_numeric($parameter)) {
         $parameter = ':p' . $parameter;
     }
     // Adapt the type
     switch ($dataType) {
         case PDO::PARAM_BOOL:
             $ociType = SQLT_INT;
             break;
         case PDO::PARAM_NULL:
             $ociType = SQLT_CHR;
             break;
         case PDO::PARAM_INT:
             $ociType = SQLT_INT;
             break;
         case PDO::PARAM_STR:
             $ociType = SQLT_CHR;
             break;
         case PDO::PARAM_LOB:
             $ociType = OCI_B_BLOB;
             $this->blobBindings[$parameter] = $variable;
             $variable = $this->connection->getNewDescriptor();
             $this->blobObjects[$parameter] =& $variable;
             break;
         case PDO::PARAM_STMT:
             $ociType = OCI_B_CURSOR;
             // Result sets require a cursor
             $variable = $this->connection->getNewCursor();
             break;
         case SQLT_NTY:
             $ociType = SQLT_NTY;
             $schema = isset($options['schema']) ? $options['schema'] : '';
             $type_name = isset($options['type_name']) ? $options['type_name'] : '';
             // set params required to use custom type.
             $variable = $this->connection->getNewCollection($type_name, $schema);
             break;
         case SQLT_CLOB:
             $ociType = OCI_B_CLOB;
             $this->blobBindings[$parameter] = $variable;
             $variable = $this->connection->getNewDescriptor();
             $this->blobObjects[$parameter] =& $variable;
             break;
         default:
             $ociType = SQLT_CHR;
             break;
     }
     if (is_array($variable)) {
         return $this->bindArray($parameter, $variable, $maxLength, $maxLength, $ociType);
     }
     $this->bindings[] =& $variable;
     return oci_bind_by_name($this->sth, $parameter, $variable, $maxLength, $ociType);
 }
Example #2
0
 /**
  * Execute an SQL query
  *
  * @param string|array $sql  SQL statement (string or array that includes
  * bind params)
  * @param array        $bind Bind parameters (if $sql is string)
  *
  * @return PDOStatement
  */
 protected function executeSQL($sql, $bind = [])
 {
     if (is_array($sql)) {
         $bind = $sql['bind'];
         $sql = $sql['string'];
     }
     if ($this->logger) {
         list(, $caller) = debug_backtrace(false);
         $this->debugSQL($caller['function'], $sql, $bind);
     }
     $sqlStmt = $this->db->prepare($sql);
     $sqlStmt->execute($bind);
     return $sqlStmt;
 }
Example #3
0
 /**
  * Binds a parameter to the specified variable name
  *
  * @param string $parameter Parameter identifier. For a prepared statement
  *   using named placeholders, this will be a parameter name of the form
  *   :name. For a prepared statement using question mark placeholders, this
  *   will be the 1-indexed position of the parameter.
  * @param mixed $variable Name of the PHP variable to bind to the SQL
  *   statement parameter.
  * @param int $dataType Explicit data type for the parameter using the
  *   PDO::PARAM_* constants.
  * @param int $maxLength Length of the data type. To indicate that a
  *   parameter is an OUT parameter from a stored procedure, you must
  *   explicitly set the length.
  * @param array $options [optional]
  * @return bool TRUE on success or FALSE on failure.
  * @todo Map PDO datatypes to oci8 datatypes and implement support for
  *   datatypes and length.
  */
 public function bindParam($parameter, &$variable, $dataType = PDO::PARAM_STR, $maxLength = -1, $options = null)
 {
     //Replace the first @oci8param to a pseudo named parameter
     if (is_numeric($parameter)) {
         $parameter = ':autoparam' . $parameter;
     }
     //Adapt the type
     switch ($dataType) {
         case PDO::PARAM_BOOL:
             $oci_type = SQLT_INT;
             break;
         case PDO::PARAM_NULL:
             $oci_type = SQLT_CHR;
             break;
         case PDO::PARAM_INT:
             $oci_type = SQLT_INT;
             break;
         case PDO::PARAM_STR:
             $oci_type = SQLT_CHR;
             break;
         case PDO::PARAM_LOB:
             $oci_type = OCI_B_BLOB;
             // create a new descriptor for blob
             $variable = $this->_pdoOci8->getNewDescriptor();
             break;
         case PDO::PARAM_STMT:
             $oci_type = OCI_B_CURSOR;
             // Result sets require a cursor
             $variable = $this->_pdoOci8->getNewCursor();
             break;
         case SQLT_NTY:
             $oci_type = SQLT_NTY;
             $schema = isset($options['schema']) ? $options['schema'] : '';
             $type_name = isset($options['type_name']) ? $options['type_name'] : '';
             // set params required to use custom type.
             $variable = oci_new_collection($this->_pdoOci8->_dbh, $type_name, $schema);
             break;
         default:
             $oci_type = SQLT_CHR;
             break;
     }
     // Bind the parameter
     $result = oci_bind_by_name($this->_sth, $parameter, $variable, $maxLength, $oci_type);
     return $result;
 }