diff --git a/index.php b/index.php index 153d2af..8243bb6 100644 --- a/index.php +++ b/index.php @@ -7,7 +7,7 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2012 * @link https://github.com/aviat4ion/OpenSQLManager - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ // -------------------------------------------------------------------------- @@ -55,7 +55,7 @@ register_shutdown_function('log_fatal'); // -------------------------------------------------------------------------- // Make sure php-gtk works -if ( ! class_exists('gtk')) +if ( ! class_exists('gtk')) { trigger_error("PHP-gtk not found. Please load the php-gtk2 extension in your php.ini", E_USER_ERROR); die(); @@ -70,7 +70,12 @@ if( ! class_exists('pdo')) // -------------------------------------------------------------------------- -// Bulk loading wrapper workaround for PHP < 5.4 +/** + * Alias for require_once for array_map + * + * @param string $path + * @return void + */ function do_include($path) { require_once($path); @@ -80,8 +85,8 @@ function do_include($path) { array_map('do_include', glob(BASE_DIR . "/common/*.php")); array_map('do_include', glob(BASE_DIR . "/db/*.php")); - array_map('do_include', glob(BASE_DIR . "/windows/widgets/*.php")); - array_map('do_include', glob(BASE_DIR . "/windows/*.php")); + array_map('do_include', glob(BASE_DIR . "/windows/widgets/*.php")); + array_map('do_include', glob(BASE_DIR . "/windows/*.php")); } // -------------------------------------------------------------------------- @@ -98,7 +103,7 @@ foreach(pdo_drivers() as $d) } $file = "{$path}{$d}.php"; - + if(is_file($file)) { require_once("{$path}{$d}.php"); @@ -113,6 +118,8 @@ if(function_exists('fbird_connect')) require_once("{$path}firebird_sql.php"); } +// -------------------------------------------------------------------------- +// ! Global Functions // -------------------------------------------------------------------------- /** diff --git a/sys/common/settings.php b/sys/common/settings.php index 1b1d815..5dee746 100644 --- a/sys/common/settings.php +++ b/sys/common/settings.php @@ -7,14 +7,14 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2012 * @link https://github.com/aviat4ion/OpenSQLManager - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ // -------------------------------------------------------------------------- /** * Class for manipulating datbase connections, and program settings - * + * * Use JSON for compatibility */ class Settings { @@ -32,14 +32,14 @@ class Settings { return self::$instance; } - + /** * Load the settings file - private so it can't be loaded * directly - the settings should be safe! */ private function __construct() { - $path = SETTINGS_DIR.'/settings.json'; + $path = SETTINGS_DIR.'/settings.json'; if( ! is_file($path)) { @@ -74,14 +74,14 @@ class Settings { /** * Magic method to simplify isset checking for config options - * + * * @param string $key - * @return $mixed + * @return mixed */ public function __get($key) { - return (isset($this->current->{$key}) && $key != "dbs") - ? $this->current->{$key} + return (isset($this->current->{$key}) && $key != "dbs") + ? $this->current->{$key} : NULL; } @@ -89,9 +89,9 @@ class Settings { /** * Magic method to simplify setting config options - * + * * @param string $key - * @param mixed $val + * @param mixed */ public function __set($key, $val) { @@ -101,7 +101,7 @@ class Settings { return FALSE; } - $this->current->{$key} = $val; + return $this->current->{$key} = $val; } // -------------------------------------------------------------------------- @@ -155,7 +155,7 @@ class Settings { /** * Remove a database connection - * + * * @param string $name */ public function remove_db($name) @@ -173,11 +173,11 @@ class Settings { } // -------------------------------------------------------------------------- - + /** * Retreive all db connections - * - * @return array + * + * @return array */ public function get_dbs() { @@ -194,7 +194,9 @@ class Settings { */ public function get_db($name) { - return (isset($this->current->dbs->{$name})) ? $this->current->dbs->{$name} : FALSE; + return (isset($this->current->dbs->{$name})) + ? $this->current->dbs->{$name} + : FALSE; } } diff --git a/sys/db/db_pdo.php b/sys/db/db_pdo.php index 9afac89..2afe424 100644 --- a/sys/db/db_pdo.php +++ b/sys/db/db_pdo.php @@ -7,7 +7,7 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2012 * @link https://github.com/aviat4ion/OpenSQLManager - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ // -------------------------------------------------------------------------- @@ -16,6 +16,8 @@ * Base Database class * * Extends PDO to simplify cross-database issues + * + * @abstract */ abstract class DB_PDO extends PDO { @@ -29,9 +31,9 @@ abstract class DB_PDO extends PDO { { parent::__construct($dsn, $username, $password, $driver_options); } - + // ------------------------------------------------------------------------- - + /** * Simplifies prepared statements for database queries * @@ -43,23 +45,23 @@ abstract class DB_PDO extends PDO { { // Prepare the sql $query = $this->prepare($sql); - + if( ! (is_object($query) || is_resource($query))) { $this->get_last_error(); return FALSE; } - + // Set the statement in the class variable for easy later access $this->statement =& $query; - - + + if( ! (is_array($data) || is_object($data))) { trigger_error("Invalid data argument"); return FALSE; } - + // Bind the parameters foreach($data as $k => $value) { @@ -67,18 +69,18 @@ abstract class DB_PDO extends PDO { { $k++; } - + $res = $query->bindValue($k, $value); - + if( ! $res) { trigger_error("Parameter not successfully bound"); return FALSE; } } - - return $query; - + + return $query; + } // ------------------------------------------------------------------------- @@ -91,7 +93,7 @@ abstract class DB_PDO extends PDO { * @return PDOStatement */ public function prepare_execute($sql, $params) - { + { $this->statement = $this->prepare_query($sql, $params); $this->statement->execute(); @@ -128,19 +130,19 @@ abstract class DB_PDO extends PDO { public function affected_rows($statement='') { if ( ! empty($statement)) - { + { $this->statement = $statement; } - + // Execute the query //$this->statement->execute(); // Return number of rows affected return $this->statement->rowCount(); } - + // -------------------------------------------------------------------------- - + /** * Return the last error for the current database connection * @@ -149,7 +151,7 @@ abstract class DB_PDO extends PDO { public function get_last_error() { $info = $this->errorInfo(); - + echo "Error:
{$info[0]}:{$info[1]}\n{$info[2]}"; } @@ -195,45 +197,45 @@ abstract class DB_PDO extends PDO { /** * Abstract public functions to override in child classes */ - + /** * Return list of tables for the current database - * + * * @return array */ abstract public function get_tables(); /** * Empty the passed table - * + * * @param string $table - * + * * @return void */ abstract public function truncate($table); /** * Return the number of rows for the last SELECT query - * + * * @return int */ abstract public function num_rows(); /** - * Retreives an array of non-user-created tables for + * Retreives an array of non-user-created tables for * the connection/database - * + * * @return array */ abstract public function get_system_tables(); - + /** * Return an SQL file with the database table structure * * @return string */ abstract public function backup_structure(); - + /** * Return an SQL file with the database data as insert statements * @@ -248,21 +250,23 @@ abstract class DB_PDO extends PDO { * Abstract parent for database manipulation subclasses */ abstract class DB_SQL { - + /** * Get database-specific sql to create a new table - * - * @param string $name - * @param array $columns - * @param array $constraints - * @param array $indexes + * + * @abstract + * @param string $name + * @param array $columns + * @param array $constraints + * @param array $indexes * @return string */ abstract public function create_table($name, $columns, array $constraints=array(), array $indexes=array()); /** * Get database-specific sql to drop a table - * + * + * @abstract * @param string $name * @return string */ @@ -271,16 +275,18 @@ abstract class DB_SQL { /** * Get database specific sql for limit clause * + * @abstract * @param string $sql * @param int $limiit * @param int $offset * @return string */ abstract public function limit($sql, $limit, $offset=FALSE); - + /** * Get the sql for random ordering * + * @abstract * @return string */ abstract public function random(); diff --git a/sys/db/drivers/firebird.php b/sys/db/drivers/firebird.php index 1c98d51..981e1d3 100644 --- a/sys/db/drivers/firebird.php +++ b/sys/db/drivers/firebird.php @@ -7,25 +7,25 @@ * @author Timothy J. Warren * @copyright Copyright (c) 2012 * @link https://github.com/aviat4ion/OpenSQLManager - * @license http://philsturgeon.co.uk/code/dbad-license + * @license http://philsturgeon.co.uk/code/dbad-license */ // -------------------------------------------------------------------------- /** * Firebird Database class - * + * * PDO-firebird isn't stable, so this is a wrapper of the fbird_ public functions. */ class firebird extends DB_PDO { protected $statement, $statement_link, $trans, $count, $result, $conn; - + /** * Open the link to the database - * + * * @param string $db - * @param string $user + * @param string $user * @param string $pass */ public function __construct($dbpath, $user='sysdba', $pass='masterkey') @@ -38,27 +38,27 @@ class firebird extends DB_PDO { throw new PDOException(fbird_errmsg()); die(); } - + $class = __CLASS__."_sql"; $this->sql = new $class; } - + // -------------------------------------------------------------------------- /** - * Close the link to the database + * Close the link to the database and any existing results */ public function __destruct() { @fbird_close(); @fbird_free_result($this->statement); } - + // -------------------------------------------------------------------------- /** * Empty a database table - * + * * @param string $table */ public function truncate($table) @@ -67,9 +67,9 @@ class firebird extends DB_PDO { $sql = 'DELETE FROM "'.$table.'"'; $this->statement = $this->query($sql); } - + // -------------------------------------------------------------------------- - + /** * Wrapper public function to better match PDO * @@ -80,7 +80,7 @@ class firebird extends DB_PDO { public function query($sql) { $this->count = 0; - + if (isset($this->trans)) { $this->statement_link = @fbird_query($this->trans, $sql); @@ -95,12 +95,12 @@ class firebird extends DB_PDO { { throw new PDOException(fbird_errmsg()); } - + return new FireBird_Result($this->statement_link); } - - - + + + // -------------------------------------------------------------------------- /** @@ -121,39 +121,39 @@ class firebird extends DB_PDO { return new FireBird_Result($this->statement_link); } - + // -------------------------------------------------------------------------- /** * List tables for the current database - * + * * @return array */ public function get_tables() - { + { $sql = <<