Skip to content

Commit

Permalink
Table prefix on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
Wazabii committed Dec 12, 2023
1 parent fcffc39 commit cdd7e3e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ $connect->setPrefix("maple_");
$connect->execute();

```

## Make queries
Start with the namespace
```php
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cdd7e3e

Please sign in to comment.