PHP code example of zobaken / daltron
1. Go to this page and download the library: Download zobaken/daltron 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/ */
zobaken / daltron example snippets
\Dal\Dal::setConfiguration([
'host' => '192.168.99.100',
'user' => 'test',
'password' => 'test',
'dbname' => 'test',
'driver' => 'mysql',
]);
return [
'host' => '192.168.99.100',
'user' => 'test',
'password' => 'test',
'dbname' => 'test',
'driver' => 'mysql',
];
\Dal\Dal::loadConfiguration('config.php');
$rows = db()->query('SELECT * FROM users')->fetchAllAssoc();
$rows = db()
->select('*')
->from('users')
->where('created_ts = ?', $time)
->fetchAllAssoc();
$query = sprintf("SELECT * FROM users WHERE created_ts < '%s'",
mysqli_real_escape_string($connection, $time)
);
$result = mysqli_query($connection, $query);
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$rows = db()->select('*')
->from('users')
->where('true')
->ifQuery($timeFrom, 'AND created_ts >= ?', $timeFrom)
->ifQuery($timeTo, 'AND created_ts < ?', $timeTo)
->ifQuery($order && $orderDirection, 'ORDER BY #? !?', $order, $orderDirection)
->ifQuery($limit, 'LIMIT ?', $limit)
->ifQuery($offset, 'OFFSET ?', $offset)
->fetchAllAssoc();
// Insert query
$row = [
'name' => 'Peter Userman',
'created_ts' => dbtime(),
'hash' => password_hash('REMEMBERME1', PASSWORD_DEFAULT),
];
$id = db()->insertRow('users', $row)
->exec(true);
// Update query
db()->update('users')
->set('hash = ?', '')
->where('id = ?', $id)
->exec();
// User needs to know
printf("Updated %d row(s)\n", db()->affectedRows());
vendor/bin/dbgen config.php model
\Dal\Dal::loadConfiguration('config.php');
$generator = \Dal\Model\GeneratorFactory::createGenerator('model');
$generator->run();
// Create new object
$user = new User();
$user->name = 'Mike Swoloch';
$user->created_ts = dbtime();
$user->hash = md5('hash');
$user->id = $user->insert(true);
// Get object from database
$user = User::get($id);
if ($user) {
// Update object
$user->name = 'Mike Sweety';
$user->update();
}
// Delete object
$user->remove();
$user = User::findRow('name = ?', 'Alexandr Flea');
$objects = User::find('created_ts < ?', dbtime('- 1 day'));
$objects = User::find('created_ts < ? LIMIT ?', dbtime('- 1 day'), 10);
$rows = User::querySelect()
->where('true')
->ifQuery($timeFrom, 'AND created_ts >= ?', $timeFrom)
->ifQuery($timeTo, 'AND created_ts < ?', $timeTo)
->ifQuery($order && $orderDirection, 'ORDER BY #? !?', $order, $orderDirection)
->ifQuery($limit, 'LIMIT ?', $limit)
->ifQuery($offset, 'OFFSET ?', $offset)
->fetchAll();
User::queryUpdate()
->set('hash = ?', '[some old man]')
->where('created_ts < ?', dbtime('- 1 month'))
->exec();
User::queryDelete()
->where('created_ts < ?', dbtime('- 1 year'))
->exec();
// Lets inform user
printf("Deleted %d row(s)\n", User::query()->affectedRows());
User::queryUpdateRow([
'name' => '[some old man]',
'hash' => md5('password'),
])
->where('created_ts < ?', dbtime('- 1 month'))
->exec();
return [
'host' => '192.168.99.100',
'user' => 'test',
'password' => 'test',
'dbname' => 'test',
'driver' => 'mysql',
'namespace' => 'UserNamespace',
];
return [
'default' => [
'host' => '192.168.99.100',
'user' => 'test',
'password' => 'test',
'dbname' => 'test',
'driver' => 'mysql',
],
'postgres' => [
'host' => '192.168.99.100',
'user' => 'test',
'password' => 'test',
'dbname' => 'test',
'driver' => 'pgsql',
],
];
$rows = db('postgres')->q('SELECT * FROM users')->fetchAll();
$generator = \Dal\Model\GeneratorFactory::createGenerator('model', 'postgres');