function is_table_exists($table, $db = NULL) { if (is_null($db)) { $db = F3::get('DB.name'); } return $db && F3::sql(array("SELECT COUNT(*) AS found " . "FROM information_schema.tables " . "WHERE table_schema='{$db}' " . "AND table_name='{$table}';")); }
public function normalize_properties_normal($table, $identifier) { $all = F3::sql("SELECT * FROM {$table}"); foreach ($all as $row) { $name = $row[$identifier]; foreach ($row as $key => $column) { echo "{$name},{$key},{$column}<br>"; } } }
public function relations() { // Select magic + class + division $division = "\n SELECT class, division\n FROM relate_loot_normal\n "; foreach (F3::sql($division) as $row) { F3::set('class', F3::get('DB.pdo')->quote($row['class'])); F3::set('division', F3::get('DB.pdo')->quote($row['division'])); $query = "\n UPDATE loot\n SET division = {@division}\n WHERE class = {@class}\n "; F3::sql($query); } }
<?php /** If our database doesn't exist, create our SQLite schema; we'll do it here programmatically; but this can be done outside of our application **/ F3::sql(array('CREATE TABLE IF NOT EXISTS kul (' . 'tc INT UNSIGNED NOT NULL,' . 'ad CHAR (15),' . 'soyad CHAR (20),' . 'PRIMARY KEY(tc)' . ');'));
/** Synchronize Axon and table structure @param $_table string @param $_id string @public **/ public function sync($_table, $_id = 'DB') { $_db =& F3::$global[$_id]; // Can't proceed until DSN is set if (!$_db || !$_db['dsn']) { trigger_error(SQLdb::TEXT_DBConnect); return; } // MySQL schema if (preg_match('/^mysql\\:/', $_db['dsn'])) { $_cmd = 'SHOW columns FROM ' . $_table . ';'; $_fields = array('Field', 'Key', 'PRI'); } elseif (preg_match('/^sqlite[2]*\\:/', $_db['dsn'])) { $_cmd = 'PRAGMA table_info(' . $_table . ');'; $_fields = array('name', 'pk', 1); } elseif (preg_match('/^(mssql|sybase|dblib|pgsql)\\:/', $_db['dsn'])) { $_cmd = 'SELECT C.column_name AS field,T.constraint_type AS key ' . 'FROM information_schema.columns C ' . 'LEFT OUTER JOIN information_schema.key_column_usage K ' . 'ON C.table_name=K.table_name AND ' . 'C.column_name=K.column_name ' . 'LEFT OUTER JOIN information_schema.table_constraints T ' . 'ON K.table_name=T.table_name AND ' . 'K.constraint_name=T.constraint_name ' . 'WHERE C.table_name="' . $_table . '";'; $_fields = array('field', 'key', 'PRIMARY KEY'); } else { trigger_error(self::TEXT_AxonEngine); return; } if (method_exists($this, 'beforeSync')) { // Execute beforeSync event $this->beforeSync(); } $_result = F3::sql($_cmd, $_id, F3::$global['SYNC']); if (!$_result) { F3::$global['CONTEXT'] = $_table; trigger_error(self::TEXT_AxonTable); return; } // Initialize Axon $this->db = $_id; $this->table = $_table; foreach ($_result as $_col) { // Populate properties $this->fields[$_col[$_fields[0]]] = NULL; if ($_col[$_fields[1]] == $_fields[2]) { // Save primary key $this->keys[$_col[$_fields[0]]] = NULL; } } $this->empty = TRUE; if (method_exists($this, 'afterSync')) { // Execute afterSync event $this->afterSync(); } }