Example #1
0
 /**
  * Binding once for multiple executions
  * Especially handy when you want to read a file into the database.
  * (see outboundResults.php for an example)
  *
  * This way of binding requires you specify the max string length of the columns
  *
  * @param array $binds
  * @param array $sizes
  * @param array $data
  * @param bool  $commit
  * @return int $errorCount
  */
 public function executeMultiple($binds, $sizes, $data, $commit = self::COMMIT)
 {
     $errorCount = 0;
     // first determine all binds once
     foreach ($binds as $i => $bind) {
         // ${trim($bind, ':')} example:  :actie_id -> $actie_id
         oci_bind_by_name($this->statement->getResource(), $bind, ${trim($bind, ':')}, $sizes[$i]);
     }
     // Then loop over all rows and give the variables the new value for that row
     // This is because the variables remain bound!
     for ($row = 0; $row < count($data); $row++) {
         foreach ($binds as $i => $bind) {
             $value = array_key_exists($i, $data[$row]) ? substr($data[$row][$i], 0, $sizes[$i]) : null;
             ${trim($bind, ':')} = trim($value);
         }
         if (!@oci_execute($this->statement->getResource(), OCI_DEFAULT)) {
             // don't commit after each row
             $errorCount++;
         }
     }
     if ($commit) {
         $this->commit();
     }
     return $errorCount;
 }
Example #2
0
 public function testResource()
 {
     $statement = new Statement("select * from test", $this->connection);
     $resource = $statement->getResource();
     $this->assertTrue(is_resource($resource));
     $this->assertEquals('oci8 statement', get_resource_type($resource));
 }
Example #3
0
 protected function setNumRows()
 {
     // oci_num_rows will return the number of fetched rows so far for a SELECT statement
     // for all other query types this is fine
     // If the user has fetched records in a while loop, the num rows will be the amount of rows fetched so far.
     // When the user hasn't fetched anything yet, we will fetch the complete result and return the count.
     $this->numRows = oci_num_rows($this->statement->getResource());
     if ($this->statement->getStatementType() == 'SELECT' && empty($this->numRows)) {
         $this->fetchAll();
         // unlike fetchResult, this will only fetch the result when result is empty
         $this->numRows = $this->result->count();
     }
 }
Example #4
0
 /**
  * Bind a variable for a procedure with an OUT parameter (size is required)
  * the out parameter can be fetched with getOutParameter($name)
  *
  * @param string $bind
  * @param string $name
  * @param int $size
  *
  * @return bool success
  */
 public function bindOutParameter($bind, $name, $size)
 {
     return oci_bind_by_name($this->statement->getResource(), $bind, $this->outParameters[$name], $size);
 }
Example #5
0
 /**
  * @param \Oracle\Query\Statement $statement
  * @param string $customMessage
  */
 public function __construct(Statement $statement, $customMessage = null)
 {
     $this->statement = $statement;
     $this->customMessage = $customMessage;
     $this->error = oci_error($statement->getResource());
 }