Skip to content

Commit cdd7e3e

Browse files
author
Wazabii
committed
Table prefix on/off
1 parent fcffc39 commit cdd7e3e

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Connect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Connect
1717
private $charSetName;
1818
private $charset = "utf8mb4";
1919
private static $self;
20-
private static $prefix;
20+
private static $prefix = "";
2121
private static $selectedDB;
2222
private static $mysqlVars;
2323

@@ -54,7 +54,7 @@ public function setCharset(string $charset): void
5454
*/
5555
public static function setPrefix(string $prefix): void
5656
{
57-
if (substr($prefix, -1) !== "_") {
57+
if (strlen($prefix) > 0 && substr($prefix, -1) !== "_") {
5858
throw new \InvalidArgumentException("The Prefix has to end with a underscore e.g. (prefix\"_\")!", 1);
5959
}
6060
self::$prefix = $prefix;

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ $connect->setPrefix("maple_");
2121
$connect->execute();
2222

2323
```
24-
2524
## Make queries
2625
Start with the namespace
2726
```php
@@ -30,10 +29,12 @@ use MaplePHP\Query\DB;
3029

3130
### Select 1:
3231
```php
33-
$select = DB::select("id,firstname,lastname", "users a")->whereId(1)->where("status", 0, ">")->limit(1);
34-
$select->join("login b", "b.user_id = a.id");
32+
$select = DB::select("id,firstname,lastname", ["users", "aliasA"])->whereId(1)->where("status", 0, ">")->limit(1);
33+
$select->join(["login", "aliasB"], "aliasB.user_id = aliasA.id");
3534
$obj = $select->get(); // Get one row result as object
3635
```
36+
*Default alias will be the table name e.g. users and login if they were not overwritten.*
37+
3738
### Select 2:
3839
```php
3940
$select = DB::select("id,name,content", "pages")->whereStatusParent(1, 0);
@@ -97,12 +98,14 @@ $select->orderRaw("id ASC, parent DESC");
9798
```
9899
### Join
99100
```php
100-
$select->join("tableName", "b.user_id = a.id"); // Default INNER join
101+
$select->join(["login", "aliasB"], ["aliasB.user_id" => "aliasA.id"]); // PROTECTED INPUT
101102
$select->join("tableName", "b.user_id = '%d'", [872], "LEFT"); // PROTECTED INPUT
102-
$select->joinInner("tableName", "b.user_id = a.id");
103-
$select->joinLeft("tableName", "b.user_id = a.id");
104-
$select->joinRight("tableName", "b.user_id = a.id");
105-
$select->joinCross("tableName", "b.user_id = a.id");
103+
$select->join("tableName", "b.user_id = a.id"); // "UNPROTECTED" INPUT
104+
105+
$select->joinInner("tableName", ["b.user_id" => "a.id"]);
106+
$select->joinLeft("tableName", ["b.user_id" => "a.id"]);
107+
$select->joinRight("tableName", ["b.user_id" => "a.id"]);
108+
$select->joinCross("tableName", ["b.user_id" => "a.id"]);
106109
```
107110
### Insert
108111
```php

0 commit comments

Comments
 (0)