PHP code example of serious / modx-evo-database
1. Go to this page and download the library: Download serious/modx-evo-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/ */
serious / modx-evo-database example snippets
$DB = new AgelxNash\Modx\Evo\Database\Database(
'localhost',
'modx',
'homestead',
'secret',
'modx_',
'utf8mb4',
'SET NAMES',
'utf8mb4_unicode_ci',
);
$DB->setDebug(true);
$DB->connect();
$table = $DB->getFullTableName('site_content');
$result = $DB->query('SELECT * FROM ' . $table . ' WHERE parent = 0 ORDER BY pagetitle DESC LIMIT 10');
// or
$result = $DB->select('*', $table, 'parent = 0', 'pagetitle DESC', '10');
// or
$result = $DB->select(
['id', 'pagetitle', 'title' => 'longtitle'],
['c' => $table],
['parent = 0'],
'ORDER BY pagetitle DESC',
'LIMIT 10'
);
foreach ($DB->makeArray($result) as $item) {
echo "\t [ DOCUMENT #ID " . $item['id'] . ' ] ' . $item['pagetitle'] . PHP_EOL;
}
$DB = new AgelxNash\Modx\Evo\Database\Database(
'localhost',
'modx',
'homestead',
'secret',
'modx_',
'utf8mb4',
'SET NAMES',
'utf8mb4_unicode_ci',
AgelxNash\Modx\Evo\Database\Drivers\IlluminateDriver::class
);
$DB->connect();
$table = $DB->getFullTableName('site_content');
$result = $DB->query('SELECT * FROM ' . $table . ' WHERE parent = 0 ORDER BY pagetitle DESC LIMIT 10');
foreach ($DB->makeArray($result) as $item) {
echo "\t [ DOCUMENT #ID " . $item['id'] . ' ] ' . $item['pagetitle'] . PHP_EOL;
}
$results = Illuminate\Database\Capsule\Manager::table('site_content')
->where('parent', '=', 0)
->orderBy('pagetitle', 'DESC')
->limit(10)
->get();
foreach ($out as $item) {
echo "\t [ DOCUMENT #ID " . $item->id . ' ] ' . $item->pagetitle . PHP_EOL;
}
$out = AgelxNash\Modx\Evo\Database\Models\SiteContent::where('parent', '=', 0)
->orderBy('pagetitle', 'DESC')
->limit(10)
->get();
foreach ($out as $item) {
echo "\t [ DOCUMENT #ID " . $item->id . ' ] ' . $item->pagetitle . PHP_EOL;
}
// create table
Illuminate\Database\Capsule\Manager::schema()->create('users', function ($table) {
$table->increments('id');
$table->string('email')->unique();
$table->timestamps();
});