/** * Configures database definitions. * * @param string|array $config Either a path to the JSON encoded * configuration file, or the configuration as an array. */ public static function configure($config) { DB::disconnectAll(); Config::load($config); }
/** * Prepares, then executes a statement and returns the number of affected * rows. * * The method is useful for updates or deletes, which do * not return anything. * * @param string $query The SQL query to execute. * @param array $arguments The arguments used to substitute params. * @return integer Number of rows affected by the query. */ public function preparedExecute($query, $arguments = array()) { DB::getConnection($this->name); // Handles transactions Event::emit(Event::QUERY_STARTED, array($query, $arguments, $this)); $stmt = $this->pdoPrepare($query, $arguments); $this->pdoExecute($query, $arguments, $stmt); Event::emit(Event::QUERY_COMPLETED, array($query, $arguments, $this, null)); return $stmt->rowCount(); }
/** Performs a prepared query and returns only a single column. */ private function singleColumnQuery($query, $args, $column) { $conn = DB::getConnection($this->meta->database); $pdo = $conn->getPDO(); $stmt = $pdo->prepare($query); $stmt->execute($args); $data = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $data[] = $row[$column]; } return $data; }