PHPackages                             bmware/dmk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. bmware/dmk

ActivePackage[Database &amp; ORM](/categories/database)

bmware/dmk
==========

MySQLi database toolkit

v2.0.2(7y ago)227GPL-3.0-or-laterPHPPHP &gt;=7

Since Jan 7Pushed 7y ago1 watchersCompare

[ Source](https://github.com/dutchalphaa/BMware-DMK)[ Packagist](https://packagist.org/packages/bmware/dmk)[ RSS](/packages/bmware-dmk/feed)WikiDiscussions Release Synced 3d ago

READMEChangelog (4)Dependencies (1)Versions (8)Used By (0)

BMware DMK
==========

[](#bmware-dmk)

BMware database management kit

composer: `composer require bmware/dmk`

there are currently 2 basic setup examples, the first is the normal db setup:

```
require_once("vendor/autoload.php");

use config\DatabaseConfig;

$database = DatabaseConfig::create([
  "servername" => "localhost",
  "username" => "root",
  "password" => "",
  "useExistingDatabase" => true,
  "databaseName" => "bmbuilder_testing"
]);
```

`DatabaseConfig::create()` takes in an array of arguments.

- servername: the base url to you local/test/production/ site
- username: the username of the database
- password: the password of the database
- useExistingDatabase: boolean, choose wether to use a pre-existing database, or make a new one
- databaseName: the name of the database that you want to use, if useExistingDatabase is false this becomes the name of the new database. Leave empty to use the default database name: bmbuilder\_testing

The second one is a WordPress based setup.

```
require_once("vendor/autoload.php");

use config\WordpressDatabaseConfig;

$database = WordpressDatabaseConfig::create();
```

*other than then the setup, using either class is the same. however, under the hood, the WordpressDatabase uses the global wpdb to make queries to the database*

---

### Queries

[](#queries)

there are currently 4 query actions prebuild with this library:

- create

```
use queries\CreateQuery;

$database->define(function($context){
  return CreateQuery::create("test")
  ->select("email", "location", "name")
  ->values("boydvree@BMware.com", "Netherlands", "boyd")
  ->values("someNoob@BMware.com", "noobland", "noob")
  ->endQuery();
});
```

- read

```
use queries\ReadQuery;

$database->define(function($context){
  return ReadQuery::create("test")
  ->select()
  ->whereEquals("email", "boydvree@BMware.com")
  ->union()
  ->select()
  ->whereLessThan("email", "boydvre@BMware.com", true)
  ->endQuery();
});
```

- update

```
use queries\UpdateQuery;

$database->define(function($context){
  return UpdateQuery::create("test")
  ->select("email")
  ->values("boydvree@BMware.com")
  ->whereEquals("email", "boydvree@BMware.com", true)
  ->endQuery();
});
```

- delete

```
use queries\DeleteQuery;

$database->define(function($context){
  return DeleteQuery::create("test")
  ->whereGreateThan("ID", "10")
  ->endQuery();
});
```

each action has its own query object with its own modifiers. all insert and where statements will automatically be turned into prepared statements.

every object has the `create(string $table)` function wich sets the table and returns a instance of the given query object.

every object has the `union(string $table = "")` function which if used creates a new instance of the given query object, and returns it. then on the end of the query, the bot of them will be put toghetter with a union. Will use the previous queries' table name if none is given

`CreateQuery`, `ReadQuery` and `DeleteQuery` have 3 "where" functions which are:

- `whereEquals(string $field, string $value, bool $notEquals = false)`: will add `"WHERE $field (!)= $value"` to the query
- `whereGreaterThan(string $field, string $value, bool $orEqualTo = false)`: will add `"WHERE $field >(=) $value"` to the query
- `whereLessThan(string $field, string $value, bool $orEqualTo = false)`: will add `"WHERE $field
