/** * Returns an array containing all of the result set rows. * * @param int $fetchMode Controls the contents of the returned array as * documented in PDOStatement::fetch. * @param mixed $fetchArgument This argument has a different meaning * depending on the value of the fetchMode parameter. * @param array $ctorArgs [optional] Arguments of custom class constructor * when the fetch_style parameter is PDO::FETCH_CLASS. * @return array Array containing all of the remaining rows in the result * set. The array represents each row as either an array of column values * or an object with properties corresponding to each column name. */ public function fetchAll($fetchMode = PDO::FETCH_BOTH, $fetchArgument = null, $ctorArgs = array()) { $this->setFetchMode($fetchMode, $fetchArgument, $ctorArgs); $this->results = array(); while ($row = $this->fetch()) { if (is_array($row) && is_resource(reset($row))) { $stmt = new Statement(reset($row), $this->connection, $this->options); $stmt->execute(); $stmt->setFetchMode($fetchMode, $fetchArgument, $ctorArgs); while ($rs = $stmt->fetch()) { $this->results[] = $rs; } } else { $this->results[] = $row; } } return $this->results; }
/** * Execute a PL/SQL Procedure and return its result. * Usage: DB::executeProcedure($procedureName, $bindings). * $bindings looks like: * $bindings = [ * 'p_userid' => $id * ]; * * @param string $procedureName * @param array $bindings * @param mixed $returnType * @return array */ public function executeProcedure($procedureName, $bindings, $returnType = PDO::PARAM_STMT) { $command = sprintf('begin %s(:%s, :cursor); end;', $procedureName, implode(', :', array_keys($bindings))); $stmt = $this->getPdo()->prepare($command); foreach ($bindings as $bindingName => &$bindingValue) { $stmt->bindParam(':' . $bindingName, $bindingValue); } $cursor = null; $stmt->bindParam(':cursor', $cursor, $returnType); $stmt->execute(); if ($returnType === PDO::PARAM_STMT) { $statement = new Statement($cursor, $this->getPdo(), $this->getPdo()->getOptions()); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC); $statement->closeCursor(); return $results; } return $cursor; }