From 89fd15a9aaf464b05db6da8454bfe69a7bb0262e Mon Sep 17 00:00:00 2001 From: emagombe Date: Fri, 6 Dec 2019 16:52:07 +0200 Subject: [PATCH] Implemented new autoload method and changed connection method to a new and more efficient one --- Examples/Delete.php | 10 ++++++++++ Examples/Example.php | 9 +++++++++ Examples/Insert.php | 9 +++++++++ Examples/Select.php | 10 ++++++++++ Examples/Truncate.php | 10 ++++++++++ Examples/Update.php | 9 +++++++++ README.md | 19 +++++++++++-------- app.conf | 6 ------ autoload.php | 17 ++++++----------- database/Database.php | 29 ++++++----------------------- queryBuilder/JsonQB.php | 5 +++++ 11 files changed, 85 insertions(+), 48 deletions(-) delete mode 100644 app.conf diff --git a/Examples/Delete.php b/Examples/Delete.php index 3fb3c72..acb6eaa 100644 --- a/Examples/Delete.php +++ b/Examples/Delete.php @@ -4,6 +4,16 @@ use queryBuilder\JsonQB as JQB; +JQB::connect([ + 'database' => '', + 'host' => '', + 'port' => '', + 'username' => '', + 'password' => '', + 'charset' => '', +]); + + $sql = JQB::Delete('user', [ 'where' => array( array( diff --git a/Examples/Example.php b/Examples/Example.php index 40a8d4f..6fcfb4e 100644 --- a/Examples/Example.php +++ b/Examples/Example.php @@ -3,6 +3,15 @@ require '../autoload.php'; +JQB::connect([ + 'database' => '', + 'host' => '', + 'port' => '', + 'username' => '', + 'password' => '', + 'charset' => '', +]); + // $qb = JsonQB::Insert('user', [ // 'value' => [ diff --git a/Examples/Insert.php b/Examples/Insert.php index d116a70..1e86448 100644 --- a/Examples/Insert.php +++ b/Examples/Insert.php @@ -4,6 +4,15 @@ use queryBuilder\JsonQB as JQB; +JQB::connect([ + 'database' => '', + 'host' => '', + 'port' => '', + 'username' => '', + 'password' => '', + 'charset' => '', +]); + $sql = JQB::Insert('user', array( "value" => array( diff --git a/Examples/Select.php b/Examples/Select.php index cadef90..ad50d6c 100644 --- a/Examples/Select.php +++ b/Examples/Select.php @@ -4,6 +4,16 @@ use queryBuilder\JsonQB as JQB; +JQB::connect([ + 'database' => '', + 'host' => '', + 'port' => '', + 'username' => '', + 'password' => '', + 'charset' => '', +]); + + $sql = JQB::Select(array( "columns" => array("user.*", "user_type.*"), "from" => array("user", "user_type"), diff --git a/Examples/Truncate.php b/Examples/Truncate.php index 5f661c6..3345d3a 100644 --- a/Examples/Truncate.php +++ b/Examples/Truncate.php @@ -4,6 +4,16 @@ use queryBuilder\JsonQB as JQB; +JQB::connect([ + 'database' => '', + 'host' => '', + 'port' => '', + 'username' => '', + 'password' => '', + 'charset' => '', +]); + + $sql = JQB::Truncate('user')->sql(); print_r($sql); diff --git a/Examples/Update.php b/Examples/Update.php index c94201c..dc2842c 100644 --- a/Examples/Update.php +++ b/Examples/Update.php @@ -4,6 +4,15 @@ use queryBuilder\JsonQB as JQB; +JQB::connect([ + 'database' => '', + 'host' => '', + 'port' => '', + 'username' => '', + 'password' => '', + 'charset' => '', +]); + $sql = JQB::Update('user', [ 'value' => array( 'username' => 'example' diff --git a/README.md b/README.md index d3f412d..38cbd73 100644 --- a/README.md +++ b/README.md @@ -20,14 +20,17 @@ require_once 'JsonQB/autoload.php'; ## Database settings -Setput your database connetion settings on **JsonQB/app.conf** file -```script -DATABASE=your_database -HOST=your_host -PORT=3306 -USERNAME=your_username -PASSWORD=your_password -CHARSET=utf8 +```php +use queryBuilder\JsonQB as JQB; + +JQB::connect([ + 'database' => '', # Database name + 'host' => '', # Host name + 'port' => '', # Connection port + 'username' => '', # Username + 'password' => '', # Password + 'charset' => '', # Charset +]); ``` ## Generating queries diff --git a/app.conf b/app.conf deleted file mode 100644 index 87dc9b5..0000000 --- a/app.conf +++ /dev/null @@ -1,6 +0,0 @@ -DATABASE=your_database -HOST=your_host -PORT=your_port -USERNAME=your_username -PASSWORD=your_password -CHARSET=utf8 \ No newline at end of file diff --git a/autoload.php b/autoload.php index 62c2b08..f7505a4 100644 --- a/autoload.php +++ b/autoload.php @@ -1,12 +1,7 @@ -read_conf(); + $config = (object) self::$connection_object; $host = $config->host; $database = $config->database; @@ -29,22 +30,4 @@ public function conn() { throw new Exception($ex->getMessage()); } } - - private function read_conf() { - $content = file_get_contents(dirname(__FILE__)."/../app.conf"); - $content = explode("\n", $content); - $config = []; - foreach($content as $item) { - $items = explode("=", $item); - $config[strtolower($items[0])] = $items[1]; - } - $settings = new Settings(); - $settings->database = str_replace("\r", '', $config['database']); - $settings->username = str_replace("\r", '', $config['username']); - $settings->password = str_replace("\r", '', $config['password']); - $settings->charset = str_replace("\r", '', $config['charset']); - $settings->host = str_replace("\r", '', $config['host']); - $settings->port = str_replace("\r", '', $config['port']); - return $settings; - } } \ No newline at end of file diff --git a/queryBuilder/JsonQB.php b/queryBuilder/JsonQB.php index cc9c8c8..22871f5 100644 --- a/queryBuilder/JsonQB.php +++ b/queryBuilder/JsonQB.php @@ -2,6 +2,7 @@ namespace queryBuilder; +use database\Database; use security\Security; use queryBuilder\query\Insert; use queryBuilder\query\Update; @@ -11,6 +12,10 @@ class JsonQB { + public static function connect($connection_object) { + Database::get_connection_object($connection_object); + } + public static function Insert($table, $request) { return new Insert($table, $request); }