2018-10-09 21:30:00 +02:00
|
|
|
<?php
|
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
require_once( __DIR__ . "/../permissions/class.permissions.php" );
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
class sql {
|
|
|
|
|
2019-04-11 01:31:28 +02:00
|
|
|
const DB_TYPES = array(
|
|
|
|
|
|
|
|
"MySQL" => "mysql",
|
2019-06-24 22:55:21 +02:00
|
|
|
"PostgreSQL" => "pgsql",
|
2019-05-28 00:18:33 +02:00
|
|
|
//"SQLite" => "sqlite",
|
2019-04-11 01:31:28 +02:00
|
|
|
);
|
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
public $connection = null;
|
2019-02-04 22:42:12 +01:00
|
|
|
public $identifier_character = null;
|
|
|
|
protected static $instance = null;
|
2018-10-09 21:30:00 +02:00
|
|
|
|
|
|
|
public function __construct() {
|
2019-02-04 22:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function close() {
|
|
|
|
|
|
|
|
$this->connection = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function connect() {
|
|
|
|
|
|
|
|
if( $this->connection == null ) {
|
|
|
|
|
|
|
|
$host = DBHOST;
|
|
|
|
$dbname = DBNAME;
|
|
|
|
$dbtype = DBTYPE;
|
|
|
|
$username = DBUSER;
|
|
|
|
$password = DBPASS;
|
2019-07-02 00:22:33 +02:00
|
|
|
$options = array(
|
|
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
|
|
);
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
$this->connection = new PDO( "{$dbtype}:host={$host};dbname={$dbname}", $username, $password, $options );
|
2019-02-04 22:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return( $this->connection );
|
|
|
|
}
|
|
|
|
|
2019-04-12 15:45:42 +02:00
|
|
|
public function create_default_tables() {
|
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$create_tables = $this->create_tables();
|
2019-07-09 04:34:39 +02:00
|
|
|
$structure_updates = $this->update_table_structure();
|
|
|
|
$result = array(
|
|
|
|
"create_tables" => $create_tables,
|
|
|
|
"structure_updates" => $structure_updates
|
|
|
|
);
|
2019-10-16 16:20:09 +02:00
|
|
|
return $result;
|
2019-04-12 15:45:42 +02:00
|
|
|
}
|
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
public function create_tables() {
|
2019-04-04 14:18:08 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$script = __DIR__ . "/scripts/" . DBTYPE . ".sql";
|
|
|
|
|
|
|
|
if( ! is_file( $script ) ) {
|
2019-04-04 14:18:08 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
return "Error, no database scripts specified for currently selected dbtype.";
|
|
|
|
}
|
2019-04-04 14:18:08 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
try {
|
2019-04-12 18:11:27 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$query = file_get_contents( $script );
|
2019-07-02 00:22:33 +02:00
|
|
|
$connection = $this->connect();
|
|
|
|
$result = $connection->exec( $query );
|
2019-04-12 18:11:27 +02:00
|
|
|
return true;
|
2019-07-02 00:22:33 +02:00
|
|
|
} catch( exception $error ) {
|
|
|
|
|
|
|
|
return $error->getMessage();
|
2019-04-12 00:26:55 +02:00
|
|
|
}
|
2019-04-04 14:18:08 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
public static function escape_identifier( $i ) {
|
|
|
|
|
|
|
|
$i = preg_replace('/[^A-Za-z0-9_]+/', '', $i );
|
2019-04-04 19:23:03 +02:00
|
|
|
return $i;
|
2018-10-09 21:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
public static function is_not_error( $i ) {
|
2018-11-10 06:41:28 +01:00
|
|
|
|
|
|
|
$return = false;
|
2019-02-04 22:42:12 +01:00
|
|
|
$result = json_decode( $i );
|
2018-11-10 06:41:28 +01:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
if ( json_last_error() !== JSON_ERROR_NONE || ( ! $i == NULL && ! $i["status"] == "error" ) ) {
|
2018-11-10 06:41:28 +01:00
|
|
|
|
|
|
|
$return = true;
|
|
|
|
}
|
|
|
|
return( $return );
|
|
|
|
}
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
public static function get_instance() {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
// If the single instance hasn't been set, set it now.
|
|
|
|
if ( null == self::$instance ) {
|
|
|
|
|
|
|
|
self::$instance = new self;
|
|
|
|
}
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
return self::$instance;
|
2018-10-09 21:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-07-09 04:34:39 +02:00
|
|
|
public function update_table_structure() {
|
|
|
|
|
|
|
|
$status_updates = array();
|
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
if( DBTYPE === "mysql" || DBTYPE === "pgsql" ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
$access_query = "INSERT INTO access( project, user, level ) VALUES ";
|
|
|
|
$projects = $this->query( "SELECT id, access FROM projects", array(), array(), "fetchAll", "exception" );
|
|
|
|
$users = $this->query( "SELECT id, username FROM users", array(), array(), "fetchAll", "exception" );
|
|
|
|
$delete = Permissions::LEVELS["delete"];
|
|
|
|
|
|
|
|
foreach( $users as $row => $user ) {
|
|
|
|
|
|
|
|
foreach( $projects as $row => $project ) {
|
|
|
|
|
|
|
|
$access = json_decode( $project["access"], true );
|
|
|
|
if( ! is_array( $access ) || empty( $access ) ) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach( $access as $granted_user ) {
|
|
|
|
|
|
|
|
if( $granted_user == $user["username"] ) {
|
|
|
|
|
|
|
|
$access_query .= "( {$project["id"]}, {$user["id"]}, $delete ),";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $access_query !== "INSERT INTO access( project, user, level ) VALUES " ) {
|
|
|
|
|
|
|
|
$result = $this->query( substr( $access_query, 0, -1 ), array(), 0, "rowCount", "exception" );
|
|
|
|
}
|
|
|
|
$result = $this->query( "ALTER TABLE projects DROP COLUMN access", array(), 0, "rowCount" );
|
|
|
|
$status_updates["access_column"] = "Cached data and removed access column.";
|
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//The access field is not there.
|
|
|
|
//echo var_export( $error->getMessage(), $access_query );
|
|
|
|
$status_updates["access_column"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "No access column to convert."
|
|
|
|
);
|
|
|
|
}
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
try {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$update_query = "";
|
|
|
|
$projects = $this->query( "SELECT id, path FROM projects", array(), array(), "fetchAll", "exception" );
|
|
|
|
$result = $this->query( "SELECT project FROM users", array(), array(), "fetchAll", "exception" );
|
|
|
|
$convert = false;
|
|
|
|
$delete = Permissions::LEVELS["delete"];
|
|
|
|
|
|
|
|
foreach( $result as $row => $user ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
if( ! is_numeric( $user["project"] ) ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$convert = true;
|
2019-07-09 04:34:39 +02:00
|
|
|
}
|
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
foreach( $projects as $row => $project ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
if( $project["path"] == $user["project"] ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$update_query .= "UPDATE users SET project={$project["id"]} WHERE username = '{$user["username"]}';";
|
2019-07-09 04:34:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
if( $convert && strlen( $update_query ) > 0 ) {
|
|
|
|
|
|
|
|
//change project to users table
|
|
|
|
$result = $this->query( "ALTER TABLE users DROP COLUMN project", array(), array(), "rowCount", "exception" );
|
|
|
|
$result = $this->query( "ALTER TABLE users ADD COLUMN project INT", array(), array(), "rowCount", "exception" );
|
|
|
|
$result = $this->query( $update_query, array(), array(), "rowCount", "exception" );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$status_updates["users_current_project"] = array( "dev_message" => "Users current project column to project_id conversion not needed." );
|
|
|
|
}
|
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//echo var_dump( $error->getMessage() );
|
|
|
|
$status_updates["users_current_project"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "Users current project column to project_id conversion failed."
|
|
|
|
);
|
2019-07-09 04:34:39 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 21:58:01 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
$this->query( array(
|
|
|
|
"mysql" => "ALTER TABLE user_options DROP INDEX name255username255;",
|
|
|
|
"pgsql" => "ALTER TABLE user_options DROP CONSTRAINT name255username255;",
|
|
|
|
), array(), 0, "rowCount", "exception" );
|
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//The access field is not there.
|
|
|
|
//echo var_export( $error->getMessage(), $access_query );
|
|
|
|
$status_updates["nameusername_user_option_constraint"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "No constriant to remove."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
try {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$update_query = "";
|
|
|
|
$options = $this->query( "SELECT id, name, username, value FROM user_options", array(), array(), "fetchAll", "exception" );
|
|
|
|
$users = $this->query( "SELECT id, username FROM users", array(), array(), "fetchAll", "exception" );
|
|
|
|
$delete = Permissions::LEVELS["delete"];
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
foreach( $users as $row => $user ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
foreach( $options as $row => $option ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
if( $option["username"] == $user["username"] ) {
|
|
|
|
|
|
|
|
$update_query .= "UPDATE user_options SET user={$user["id"]} WHERE id={$option["id"]};";
|
|
|
|
}
|
2019-07-09 04:34:39 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-16 16:20:09 +02:00
|
|
|
|
|
|
|
if( strlen( $update_query ) > 0 ) {
|
|
|
|
|
|
|
|
//change project to users table
|
|
|
|
$result = $this->query( "ALTER TABLE user_options DROP COLUMN username", array(), array(), "rowCount", "exception" );
|
|
|
|
$result = $this->query( "ALTER TABLE user_options ADD COLUMN user INT", array(), array(), "rowCount", "exception" );
|
|
|
|
$result = $this->query( $update_query, array(), array(), "rowCount", "exception" );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$status_updates["username_user_option_column"] = array( "dev_message" => "User options username column needed no conversion." );
|
|
|
|
}
|
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//The access field is not there.
|
|
|
|
//echo var_export( $error->getMessage(), $access_query );
|
|
|
|
$status_updates["username_user_option_column"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "No username column to convert."
|
|
|
|
);
|
2019-07-09 04:34:39 +02:00
|
|
|
}
|
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
try {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
$result = $this->query( "ALTER TABLE users DROP COLUMN groups", array(), array(), "rowCount", "exception" );
|
|
|
|
$status_updates["users_groups_column"] = array( "dev_message" => "Removal of the groups column from the users table succeeded." );
|
|
|
|
} catch( Exception $error ) {
|
2019-07-09 04:34:39 +02:00
|
|
|
|
2019-10-16 16:20:09 +02:00
|
|
|
//echo var_dump( $error->getMessage() );
|
|
|
|
$status_updates["users_groups_column"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "Removal of the groups column from the users table failed. This usually means there was never one to begin with"
|
|
|
|
);
|
2019-07-09 04:34:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
2019-07-17 21:14:27 +02:00
|
|
|
$projects = $this->query( array(
|
|
|
|
"mysql" => "ALTER TABLE projects DROP INDEX path1500owner255;",
|
|
|
|
"pgsql" => "ALTER TABLE projects DROP CONSTRAINT path1500owner255;",
|
|
|
|
), array(), 0, "rowCount", "exception" );
|
2019-07-09 04:34:39 +02:00
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//echo var_dump( $error->getMessage() );
|
|
|
|
$status_updates["path_owner_constraint"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "Removal of path1500owner255 constraint in the projects table failed. This usually means there was never one to begin with"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-18 21:58:01 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
$convert = false;
|
|
|
|
$update_query = "";
|
|
|
|
$projects = $this->query( "SELECT id, name, path, owner FROM projects", array(), array(), "fetchAll", "exception" );
|
|
|
|
$users = $this->query( "SELECT id, username FROM users", array(), array(), "fetchAll", "exception" );
|
|
|
|
$delete = Permissions::LEVELS["delete"];
|
|
|
|
|
|
|
|
foreach( $projects as $row => $project ) {
|
|
|
|
|
|
|
|
if( ! is_numeric( $project["owner"] ) ) {
|
|
|
|
|
|
|
|
$convert = true;
|
|
|
|
}
|
|
|
|
|
2019-10-24 14:56:24 +02:00
|
|
|
$current_user = null;
|
|
|
|
|
2019-10-18 21:58:01 +02:00
|
|
|
foreach( $users as $row => $user ) {
|
|
|
|
|
|
|
|
if( $project["owner"] == $user["username"] ) {
|
|
|
|
|
|
|
|
$update_query .= "UPDATE projects SET owner={$user["id"]} WHERE id={$project["id"]};";
|
2019-10-24 14:56:24 +02:00
|
|
|
$current_user = $user;
|
2019-10-18 21:58:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 14:56:24 +02:00
|
|
|
if( $current_user != null && $project["owner"] != $current_user["username"] ) {
|
2019-10-18 21:58:01 +02:00
|
|
|
|
|
|
|
$update_query .= "UPDATE projects SET owner=-1 WHERE id={$project["id"]};";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( strlen( $update_query ) > 0 && $convert ) {
|
|
|
|
|
|
|
|
//change project to users table
|
|
|
|
$result = $this->query( "ALTER TABLE projects DROP COLUMN owner", array(), array(), "rowCount", "exception" );
|
|
|
|
$result = $this->query( "ALTER TABLE projects ADD COLUMN owner INT", array(), array(), "rowCount", "exception" );
|
|
|
|
$result = $this->query( $update_query, array(), array(), "rowCount", "exception" );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$status_updates["owner_projects_column"] = array( "dev_message" => "User projects owner column needed no conversion." );
|
|
|
|
}
|
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//The access field is not there.
|
|
|
|
//echo var_export( $error->getMessage(), $access_query );
|
|
|
|
$status_updates["username_user_option_column"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "No username column to convert."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-09 04:34:39 +02:00
|
|
|
try {
|
|
|
|
|
2019-07-17 21:14:27 +02:00
|
|
|
$projects = $this->query( array(
|
|
|
|
"mysql" => "ALTER TABLE active DROP INDEX username255path1500;",
|
|
|
|
"pgsql" => "ALTER TABLE active DROP CONSTRAINT username255path1500;",
|
|
|
|
), array(), 0, "rowCount", "exception" );
|
2019-07-09 04:34:39 +02:00
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//echo var_dump( $error->getMessage() );
|
|
|
|
$status_updates["username_path_constraint"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "Removal of username255path1500 constraint in the active table failed. This usually means there was never one to begin with"
|
|
|
|
);
|
|
|
|
}
|
2019-10-18 21:58:01 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
$result = $this->query( "DELETE FROM active;", array(), 0, "rowCount", "exception" );
|
|
|
|
$result = $this->query( "ALTER TABLE active DROP COLUMN username;", array(), 0, "rowCount", "exception" );
|
|
|
|
$result = $this->query( "ALTER TABLE active ADD COLUMN user INT", array(), array(), "rowCount", "exception" );
|
|
|
|
} catch( Exception $error ) {
|
|
|
|
|
|
|
|
//echo var_dump( $error->getMessage() );
|
|
|
|
$status_updates["username_active_coluin"] = array(
|
|
|
|
"error_message" => $error->getMessage(),
|
|
|
|
"dev_message" => "Removal of username255path1500 constraint in the active table failed. This usually means there was never one to begin with"
|
|
|
|
);
|
|
|
|
}
|
2019-07-09 04:34:39 +02:00
|
|
|
}
|
|
|
|
return $status_updates;
|
|
|
|
}
|
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
public function query( $query, $bind_variables, $default, $action='fetchAll', $errors="default" ) {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
/**
|
|
|
|
* Errors:
|
|
|
|
* default - this value could be anything such as true or foobar
|
|
|
|
* message
|
|
|
|
* exception
|
|
|
|
*/
|
|
|
|
|
2019-07-17 18:14:10 +02:00
|
|
|
if( is_array( $query ) ) {
|
|
|
|
|
|
|
|
if( in_array( DBTYPE, array_keys( $query ) ) ) {
|
|
|
|
|
|
|
|
$query = $query[DBTYPE];
|
|
|
|
} else {
|
|
|
|
|
2019-07-17 21:14:27 +02:00
|
|
|
if( isset( $query["*"] ) ) {
|
|
|
|
|
|
|
|
$query = $query["*"];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$return = $default;
|
|
|
|
|
|
|
|
if( $errors == "message" ) {
|
|
|
|
|
|
|
|
$return = json_encode( array( "error" => "No query specified for database type." ) );
|
|
|
|
} elseif( $errors == "exception" ) {
|
|
|
|
|
|
|
|
throw new Error( "No query specified for database type." );
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
2019-07-17 18:14:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
try {
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
$connection = $this->connect();
|
|
|
|
$statement = $connection->prepare( $query );
|
|
|
|
$statement->execute( $bind_variables );
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
switch( $action ) {
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
case( 'rowCount' ):
|
|
|
|
|
|
|
|
$return = $statement->rowCount();
|
|
|
|
break;
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2019-07-02 22:46:32 +02:00
|
|
|
case( 'fetch' ):
|
|
|
|
|
|
|
|
$return = $statement->fetch( \PDO::FETCH_ASSOC );
|
|
|
|
break;
|
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
case( 'fetchAll' ):
|
|
|
|
|
|
|
|
$return = $statement->fetchAll( \PDO::FETCH_ASSOC );
|
|
|
|
break;
|
2019-02-04 22:42:12 +01:00
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
case( 'fetchColumn' ):
|
|
|
|
|
|
|
|
$return = $statement->fetchColumn();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
$return = $statement->fetchAll( \PDO::FETCH_ASSOC );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch( exception $error ) {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$return = $default;
|
2019-04-15 20:38:54 +02:00
|
|
|
|
2019-07-02 00:22:33 +02:00
|
|
|
if( $errors == "message" ) {
|
|
|
|
|
|
|
|
$return = json_encode( array( $error->getMessage() ) );
|
|
|
|
} elseif( $errors == "exception" ) {
|
|
|
|
|
|
|
|
throw $error;
|
|
|
|
}
|
2019-04-15 20:38:54 +02:00
|
|
|
}
|
2019-02-04 22:42:12 +01:00
|
|
|
$this->close();
|
2018-10-09 21:30:00 +02:00
|
|
|
return( $return );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|