54 lines
1.2 KiB
PHP
54 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: Database Helper
|
|
* Version: 1.0
|
|
* Author: Jan-Niclas Loosen (Loosen-IT and Designraketen GmbH)
|
|
* Author URI: https://example.com
|
|
* License: MIT
|
|
*/
|
|
|
|
use DatabaseHelper\Database;
|
|
use DatabaseHelper\enums\Order;
|
|
use DatabaseHelper\enums\Type;
|
|
|
|
try {
|
|
require 'build.php';
|
|
|
|
$table = Database::makeTable('testing-table')
|
|
->primary('col-primary', Type::INT, autoInc: true)
|
|
->column('col-one', Type::BOOL)
|
|
->column('col-two', Type::STRING)
|
|
->create();
|
|
|
|
$batches = [
|
|
[
|
|
['col-one', true],
|
|
['col-two', 'EXPLODING!!!']
|
|
],
|
|
[
|
|
['col-one', false],
|
|
['col-two', 'EXPLODING!!!']
|
|
],
|
|
];
|
|
|
|
$batchInsert = Database::makeInsertion($table);
|
|
foreach($batches as $batch) {
|
|
$batchInsert->batchData($batch)->stack();
|
|
}
|
|
$batchInsert->insert();
|
|
|
|
Database::makeUpdate($table)
|
|
->where('col-primary', '=', 1)
|
|
->set('col-one', false)
|
|
->update();
|
|
|
|
$results = Database::makeQuery($table)
|
|
->select('col-primary', 'col-one')
|
|
->where('col-one', '=', true)
|
|
->orderBy('col-one', Order::DESC)
|
|
->query();
|
|
}
|
|
catch ( Exception $e ) {
|
|
echo $e->getMessage();
|
|
}
|