From cdd7e3ef79f750b3455dace79830dd926248b923 Mon Sep 17 00:00:00 2001 From: Wazabii Date: Tue, 12 Dec 2023 14:34:56 +0100 Subject: [PATCH] Table prefix on/off --- Connect.php | 4 ++-- README.md | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Connect.php b/Connect.php index 121aa24..5b42126 100755 --- a/Connect.php +++ b/Connect.php @@ -17,7 +17,7 @@ class Connect private $charSetName; private $charset = "utf8mb4"; private static $self; - private static $prefix; + private static $prefix = ""; private static $selectedDB; private static $mysqlVars; @@ -54,7 +54,7 @@ public function setCharset(string $charset): void */ public static function setPrefix(string $prefix): void { - if (substr($prefix, -1) !== "_") { + if (strlen($prefix) > 0 && substr($prefix, -1) !== "_") { throw new \InvalidArgumentException("The Prefix has to end with a underscore e.g. (prefix\"_\")!", 1); } self::$prefix = $prefix; diff --git a/README.md b/README.md index 5dd8ac9..70330dc 100755 --- a/README.md +++ b/README.md @@ -21,7 +21,6 @@ $connect->setPrefix("maple_"); $connect->execute(); ``` - ## Make queries Start with the namespace ```php @@ -30,10 +29,12 @@ use MaplePHP\Query\DB; ### Select 1: ```php -$select = DB::select("id,firstname,lastname", "users a")->whereId(1)->where("status", 0, ">")->limit(1); -$select->join("login b", "b.user_id = a.id"); +$select = DB::select("id,firstname,lastname", ["users", "aliasA"])->whereId(1)->where("status", 0, ">")->limit(1); +$select->join(["login", "aliasB"], "aliasB.user_id = aliasA.id"); $obj = $select->get(); // Get one row result as object ``` +*Default alias will be the table name e.g. users and login if they were not overwritten.* + ### Select 2: ```php $select = DB::select("id,name,content", "pages")->whereStatusParent(1, 0); @@ -97,12 +98,14 @@ $select->orderRaw("id ASC, parent DESC"); ``` ### Join ```php -$select->join("tableName", "b.user_id = a.id"); // Default INNER join +$select->join(["login", "aliasB"], ["aliasB.user_id" => "aliasA.id"]); // PROTECTED INPUT $select->join("tableName", "b.user_id = '%d'", [872], "LEFT"); // PROTECTED INPUT -$select->joinInner("tableName", "b.user_id = a.id"); -$select->joinLeft("tableName", "b.user_id = a.id"); -$select->joinRight("tableName", "b.user_id = a.id"); -$select->joinCross("tableName", "b.user_id = a.id"); +$select->join("tableName", "b.user_id = a.id"); // "UNPROTECTED" INPUT + +$select->joinInner("tableName", ["b.user_id" => "a.id"]); +$select->joinLeft("tableName", ["b.user_id" => "a.id"]); +$select->joinRight("tableName", ["b.user_id" => "a.id"]); +$select->joinCross("tableName", ["b.user_id" => "a.id"]); ``` ### Insert ```php