1. Go to this page and download the library: Download wilkques/database library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$db->from('<table name1>')->joinSub(
function ($query) {
$query->table('<table name2>');
// do something
},
'<as name2>',
function (\Wilkques\Database\Queries\JoinClause $join) {
$join->on('<table name1>.<column1>', '<as name2>.<column1>')
->orOn('<table name1>.<column2>', '<as name2>.<column2>');
}
);
// output: select ... join (select ...) as `<as name2>` ON <table name1>.<column1> = <as name2>.<column1> OR <table name1>.<column2> = <as name2>.<column2>
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->from('<table name1>')->joinSub(
$dbTable,
'<as name2>',
function (\Wilkques\Database\Queries\JoinClause $join) {
$join->on('<table name1>.<column1>', '<as name2>.<column1>')
->orOn('<table name1>.<column2>', '<as name2>.<column2>');
}
);
// output: select ... join (select ...) as `<as name2>` ON <table name1>.<column1> = <as name2>.<column1> OR <table name1>.<column2> = <as name2>.<column2>
$db->from('<table name1>')->joinSubWhere(
function ($builder) {
$builder->table('<table name2>');
// do something
},
'<as name2>',
function (\Wilkques\Database\Queries\JoinClause $join) {
$join->on('<table name1>.<column1>', '<as name2>.<column1>')
->orOn('<table name1>.<column2>', '<as name2>.<column2>');
}
);
// output: select ... join (select ...) as `<as name2>` WHERE <table name1>.<column1> = <as name2>.<column1> OR <table name1>.<column2> = <as name2>.<column2>
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->from('<table name1>')->joinSubWhere(
$dbTable,
'<as name2>',
function (\Wilkques\Database\Queries\JoinClause $join) {
$join->on('<table name1>.<column1>', '<as name2>.<column1>')
->orOn('<table name1>.<column2>', '<as name2>.<column2>');
}
);
// output: select ... join (select ...) as `<as name2>` WHERE <table name1>.<column1> = <as name2>.<column1> OR <table name1>.<column2> = <as name2>.<column2>
$db->where([
['<columnName1>'],
['<columnName2>'],
['<columnName3>'],
]);
// output: select ... where (<columnName1> IS NULL AND <columnName2> IS NULL AND <columnName3> IS NULL)
// or
$db->where('<columnName1>');
// output: select ... where (<columnName1> IS NULL)
// or
$db->where([
['<columnName1>', '<value1>'],
['<columnName2>', '<value2>'],
['<columnName3>', '<value3>'],
]);
// or
$db->where([
['<columnName1>', '<operator1>', '<value1>'],
['<columnName2>', '<operator2>', '<value2>'],
['<columnName3>', '<operator3>', '<value3>'],
]);
// or
$db->where('<columnName1>', "<operator>", '<columnValue1>');
// or
$db->where('<columnName1>', '<value1>')
->where('<columnName2>', '<value2>')
->where('<columnName3>', '<value3>');
// or
$db->where('<columnName1>', "<operator>", '<value1>')
->where('<columnName2>', "<operator>", '<value2>')
->where('<columnName3>', "<operator>", '<value3>');
// or
$db->where(function ($query) {
$query->where('<columnName1>', '<value1>')->where('<columnName2>', '<value2>');
});
// output: select ... where (<columnName1> = <value1> AND <columnName2> = <value2>)
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->where($dbTable);
// same
$db->whereExists($dbTable);
// output: select ... where EXISTS (select ...)
// or
$db->where('<columnName>', $dbTable);
// output: select ... where '<columnName>' = (select ...)
// or
$db->where('<columnName>', "<operator>", $dbTable);
// output: select ... where '<columnName>' <operator> (select ...)
// or
$db->where('<columnName>', "<operator>", function ($query) {
$query->table('<table name>')->where('<columnName1>', '<value1>')->where('<columnName2>', '<value2>');
});
// output: select ... where '<columnName>' <operator> (select ...)
$db->whereNull('<columnName1>');
$db->whereIn('<columnName1>', ['<columnValue1>', '<columnValue2>']);
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->whereIn('<columnName1>', $dbTable);
// or
$db->whereIn('<columnName1>', function ($query) {
$query->select('<columnName2>')->table('<table name1>');
});
$db->whereExists(
function ($query) {
$query->table('<table name>');
// do something
});
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->whereExists($dbTable);
// same
$db->where($dbTable);
$db->having(`<columnName1>`, `<columnValue1>`);
// or
$db->having(`<columnName1>`, "<operator>", `<columnValue1>`);
// or
$db->having(
`<columnName1>`,
function ($query) {
$query->table('<table name>');
// do something
}
);
// or
$db->having(
`<columnName1>`,
"<operator>",
function ($query) {
$query->table('<table name>');
// do something
}
);
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->having(`<columnName1>`, $dbTable);
// or
$db->having(`<columnName1>`, "<operator>", $dbTable);
$db->orHaving(`<columnName1>`, `<columnValue1>`);
// or
$db->orHaving(`<columnName1>`, "<operator>", `<columnValue1>`);
// or
$db->orHaving(
`<columnName1>`,
function ($query) {
$query->table('<table name>');
// do something
}
);
// or
$db->orHaving(
`<columnName1>`,
"<operator>",
function ($query) {
$query->table('<table name>');
// do something
}
);
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->orHaving(`<columnName1>`, $dbTable);
// or
$db->orHaving(`<columnName1>`, "<operator>", $dbTable);
$db->limit(1); // set query LIMIT
// or
$db->limit(10, 1); // set query LIMIT
$db->offset(1); // set query OFFSET
$db->groupBy('<columnName1>', 'DESC'); // default ASC
// or
$db->groupBy([
['<columnName1>', 'DESC'],
['<columnName2>', 'ASC'],
]);
// or
$db->groupBy([
[
function ($query) {
$query->table('<table name>');
// do something
},
'DESC'
],
['<columnName2>', 'ASC'],
]);
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->groupBy($dbTable, 'DESC'); // default ASC
// or
$db->groupBy([
[
$dbTable,
'DESC'
],
['<columnName2>', 'ASC'],
]);
$db->groupByDesc('<columnName1>');
// or
$db->groupByDesc('<columnName1>', '<columnName2>');
// or
$db->groupByDesc(
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
);
// or
$db->groupByDesc(['<columnName1>', '<columnName2>']);
// or
$db->groupByDesc([
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
]);
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->groupByDesc($dbTable, '<columnName1>'); // default ASC
// or
$db->groupByDesc([
$dbTable,
'<columnName1>'
]);
$db->groupByAsc('<columnName1>');
// or
$db->groupByAsc('<columnName1>', '<columnName2>');
// or
$db->groupByAsc(
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
);
// or
$db->groupByAsc(['<columnName1>', '<columnName2>']);
// or
$db->groupByAsc([
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
]);
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->groupByAsc($dbTable, '<columnName1>'); // default ASC
// or
$db->groupByAsc([
$dbTable,
'<columnName1>'
]);
$db->orderBy('<columnName1>', "DESC"); // default ASC
// or
$db->orderBy([
['<columnName1>', 'DESC'],
['<columnName2>', 'ASC'],
]);
// or
$db->orderBy([
[
function ($query) {
$query->table('<table name>');
// do something
},
'DESC'
],
['<columnName2>', 'ASC'],
]);
$db->orderByDesc('<columnName1>');
// or
$db->orderByDesc('<columnName1>', '<columnName2>');
// or
$db->orderByDesc(
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
);
// or
$db->orderByDesc(['<columnName1>', '<columnName2>']);
// or
$db->orderByDesc([
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
]);
$db->orderByAsc('<columnName1>');
// or
$db->orderByAsc('<columnName1>', '<columnName2>');
// or
$db->orderByAsc(
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
);
// or
$db->orderByAsc(['<columnName1>', '<columnName2>']);
// or
$db->orderByAsc([
function ($query) {
$query->table('<table name>');
// do something
},
'<columnName2>'
]);
$db->union(function ($query) {
$query->table('<table name>');
// do something
});
// or
$dbTable = (
new \Wilkques\Database\Queries\Builder(
$connection,
new \Wilkques\Database\Queries\Grammar\Drivers\MySql,
new \Wilkques\Database\Queries\Processors\Processor,
)
)->table('<table name1>');
$db->union($dbTable);
$db->get(); // get all data
$db->first(); // get first data
$db->find('<id>'); // get find data
$db->where('<columnName1>', "=", '<columnValue1>')
->update([
'<updateColumnName1>' => '<updateColumnValue1>'
]);
// or
$db->where('<columnName1>', "=", '<columnValue1>')->first();
$db->update([
'<updateColumnName1>' => '<updateColumnValue1>'
]);
// or
$db->where('<columnName1>', "=", '<columnValue1>')->first();
$db->update([
'<updateColumnName1>' => function ($query) {
$query->table('<table name>')->select('<column name>');
// do something
}
]);
$db->increment('<columnName>');
// or
$db->increment('<columnName>', '<numeric>', [
'<update column 1>' => 'update value 1',
'<update column 2>' => 'update value 2',
...
]);
$db->decrement('<columnName>');
// or
$db->decrement('<columnName>', '<numeric>', [
'<update column 1>' => 'update value 1',
'<update column 2>' => 'update value 2',
...
]);