/** * Get the table definition as an associative array * @return array|null */ public function _getDef() { if (isset(self::$_globalTableData[$this->_table])) { return $this->_tableData = self::$_globalTableData[$this->_table]; } if (!isset($this->_table) || $this->_table === '') { return; } //load from cache /*if(Cache::data('mysql:def:' . get_class($this))){ return Cache::data('mysql:def:' . get_class($this)); }*/ $sql = "SHOW COLUMNS FROM `{$this->_table}`"; $result = Database::connection($this->_connection)->query($sql); if ($result) { foreach ($result as $row) { $field_name = $row['Field']; $primary = false; if ($row['Key'] == 'PRI') { $primary = true; } $type = $row['Type']; $this->_tableData[] = array('field_name' => $field_name, 'type' => $type, 'primary' => $primary); } return self::$_globalTableData[$this->_table] = $this->_tableData; //Cache::data('mysql:def:' . get_class($this), $this->_tableData); } return NULL; }
/** * Finish out our schema change by adding any indexes, and foreign keys */ public static function finish() { foreach (self::$references as $reference) { Database::connection(self::$connection)->query($reference->getQuery()); } }
/** * Ping the database connection * @return bool */ public function ping() { return Database::connection('default')->ping(); }
/** * Prepare a statement * @param string $query * @return mixed * @throws InvalidQueryException */ protected function _prepare($query) { $i = 0; foreach ($this->getParameters() as $parameter) { $field = 'field' . $i; ${$field} = $parameter['value']; $paramValues[] = ${$field}; $i++; } $stmt = Database::connection($this->connection)->prepare($query, $paramValues); if (!$stmt) { throw new InvalidQueryException('Failed to prepare statement: ' . $query); } return $stmt; }