diff --git a/src/databases/db_pdo.php b/src/databases/db_pdo.php new file mode 100644 index 0000000..6677526 --- /dev/null +++ b/src/databases/db_pdo.php @@ -0,0 +1,117 @@ +prepare($sql); + + if( ! is_like_array($query)) + { + $this->get_last_error(); + return FALSE; + } + + // Set the statement in the class variable for easy later access + $this->statement =& $query; + + + if( ! is_like_array($data)) + { + trigger_error("Invalid data argument"); + return FALSE; + } + + // Bind the parameters + foreach($data as $k => $value) + { + $res = $query->bindValue($k, $value); + + if( ! $res) + { + trigger_error("Parameter not successfully bound"); + return FALSE; + } + } + + return $query; + + } + + // ------------------------------------------------------------------------- + + /** + * Retreives the data from a select query + * + * @param PDOStatement $statement + * @return array + */ + function get_query_data($statement) + { + // Execute the query + $statement->execute(); + + // Return the data array fetched + return $statement->fetchAll(PDO::FETCH_ASSOC); + } + + // ------------------------------------------------------------------------- + + /** + * Returns number of rows affected by an INSERT, UPDATE, DELETE type query + * + * @param PDOStatement $statement + * @return int + */ + function affected_rows($statement) + { + // Execute the query + $statement->execute(); + + // Return number of rows affected + return $statement->rowCount(); + } + + // ------------------------------------------------------------------------- + + abstract function create_database($name){} + + + +} + +// End of db_pdo.php \ No newline at end of file diff --git a/src/databases/mysql.php b/src/databases/mysql.php index e974850..10aa5aa 100644 --- a/src/databases/mysql.php +++ b/src/databases/mysql.php @@ -21,9 +21,12 @@ class MySQL extends DB_PDO { function __construct($dsn, $username=null, $password=null, $options=array()) { + $options = array_merge(array( + + ), + $options); + parent::__construct("mysql:$dsn", $username, $password, $options); - - } /** @@ -33,7 +36,9 @@ class MySQL extends DB_PDO { */ function truncate($table) { - + $sql = "TRUNCATE `{$table}`"; + + $this->query($sql); } } \ No newline at end of file diff --git a/src/windows/add_db.php b/src/windows/add_db.php index d54e731..4221efc 100644 --- a/src/windows/add_db.php +++ b/src/windows/add_db.php @@ -119,6 +119,7 @@ class Add_DB extends GtkWindow { // Replace default capitalization with something that looks better. $d = str_replace("sql", "SQL", $d); $d = str_ireplace("pg", "Postgre", $d); + $d = str_ireplace("odbc", "ODBC", $d); $d = ucfirst($d); $drivers[] = $d;