Skip to content
Krzysztof Żyłka edited this page Dec 30, 2022 · 7 revisions

Table

Set table name (for select etc.) [>= 1.0.0]

$table = (new Table())->setName('table_name');

Get / Set ID [>= 1.0.0]

$table = (new Table())->setName('table_name');

$id = $table->getId(); //get id (insert)
$table->setId('int'); //set id (update)

Select

Find [>= 1.0.0]

See Condition

use \krzysztofzylka\DatabaseManager\Condition;

$table = (new Table())->setName('table_name');

$conditions = new Condition(); //conditions not required
$find = $table->find($conditions);

/**
 * example find
 * [
 *   'table_name' => [
 *     'id' => 1,
 *     'name' => 'string'
 *   ]
 * ]
 */

Find all [>= 1.0.0]

See Condition

use \krzysztofzylka\DatabaseManager\Condition;

$table = (new Table())->setName('table_name');

$conditions = new Condition(); //conditions not required
$find = $table->findAll($conditions);

/**
 * example findAll
 * [
 *   0 => [
 *     'table_name' => [
 *       'id' => 1,
 *       'name' => 'string'
 *     ]
 *   ]
 * ]
 */

Find count [>= 1.0.0]

See Condition

use \krzysztofzylka\DatabaseManager\Condition;

$table = (new Table())->setName('table_name');

$condition = new Condition();
$count = $table->findCount($condition); // int, condition is not required

Find isset [>= 1.0.0]

See Condition

use \krzysztofzylka\DatabaseManager\Condition;

$table = (new Table())->setName('table_name');

$condition = (new Condition())->where('login', 'admin'); //isset user in database
$isset = $table->findCount($condition); // bool, condition is not required

Insert [>= 1.0.0]

See Condition

$table = (new Table())->setName('table_name');

$table->insert([
    'column1' => 'value1',
    'column2' => 'value2'
]); //return true or false

$insertId = $table->getId(); //insert ID

Update

Standard [>= 1.0.0]

$table = (new Table())->setName('table_name')->setId(1);

$table->update([
    'column1' => 'updated column1',
    'column2' => 'updated column2'
]); //return true or false

Single column [>= 1.0.0]

$table = (new Table())->setName('table_name')->setId(1);

$table->updateValue('column1', 'new value'); //return bool

Delete [>= 1.0.0]

$table = (new Table())->setName('table_name');

$table->setId(2)->delete(); // delete item id=2
$table->delete(6); //delete item id=6

Get columns list [>= 1.0.0]

$columnName = null; //get single column data, default null
$table = (new Table())->setName('table_name')->columnList($columnName);

Response value (for MySQL and SQLite): https://dev.mysql.com/doc/refman/8.0/en/show-columns.html