conn = $conn; } // -------------------------------------------------------------------------- /** * Enable calling driver methods * * @param string $method * @param array $args * @return mixed */ public function __call($method, $args) { return call_user_func_array(array($this->conn, $method), $args); } // -------------------------------------------------------------------------- // ! Abstract Methods // -------------------------------------------------------------------------- /** * Convienience public function to generate sql for creating a db table * * @param string $name * @param array $fields * @param array $constraints * @param array $indexes * * @return string */ public function create_table($name, $fields, array $constraints=array(), array $indexes=array()) { $column_array = array(); // Reorganize into an array indexed with column information // Eg $column_array[$colname] = array( // 'type' => ..., // 'constraint' => ..., // 'index' => ..., // ) foreach($fields as $colname => $type) { $column_array[$colname] = array(); $column_array[$colname]['type'] = ($type !== $colname) ? $type : ''; } if( ! empty($constraints)) { foreach($constraints as $col => $const) { $column_array[$col]['constraint'] = $const; } } // Join column definitons together $columns = array(); foreach($column_array as $n => $props) { $str = '"'.$n.'"'; $str .= (isset($props['type'])) ? " {$props['type']}" : ""; $str .= (isset($props['constraint'])) ? " {$props['constraint']}" : ""; $columns[] = $str; } // Generate the sql for the creation of the table $sql = 'CREATE TABLE "'.$name.'" ('; $sql .= implode(', ', $columns); $sql .= ')'; return $sql; } /** * Get database-specific sql to drop a table * * @abstract * @param string $name * @return string */ abstract public function delete_table($name); /** * Return an SQL file with the database table structure * * @abstract * @return string */ abstract public function backup_structure(); /** * Return an SQL file with the database data as insert statements * * @abstract * @return string */ abstract public function backup_data(); } // End of db_util.php