Пример #1
0
// Add some users, two steps since must use salt as created before.
//
$sql = <<<EOD
UPDATE
    {$options['table_prefix']}{$tableName}
    SET
        password = md5(concat(salt, ?))
    WHERE
        username = ?;
EOD;
$db->execute($sql, ['doe', 'doe']);
$db->execute($sql, ['admin', 'admin']);
//
// Check whats in the db
//
$db->select("*")->from($tableName);
$res = $db->executeFetchAll();
echo "<pre>" . print_r($res, 1) . "</pre>";
//
// Check password for each user
//
$db->select("username")->from($tableName)->where("username = ?")->andWhere("password = md5(concat(salt, ?))");
$res = $db->executeFetchAll(['doe', 'doe']);
echo "<pre>" . print_r($res, 1) . "</pre>";
//
// Check password for each user
//
$db->select("username")->from($tableName)->where("username = ?")->andWhere("password = md5(concat(salt, ?))");
$res = $db->executeFetchAll(['admin', 'admin']);
echo "<pre>" . print_r($res, 1) . "</pre>";
//
Пример #2
0
$db->update('test', ['age' => 22, 'text' => "Mumintrollet", 'text2' => "Mumindalen"], "id = 2");
echo "<pre>" . $db->getSQL() . "</pre>";
//
// Update a single row using two arrays
//
$db->update('test', ['age', 'text', 'text1'], [22, "Mumintrollet", "Mumindalen"], "id = 2");
echo "<pre>" . $db->getSQL() . "</pre>";
//
// Update a single row into table using one array (rest will be sent as parameters)
//
$db->update('test', ['age', 'text', 'text1'], "id = ?");
echo "<pre>" . $db->getSQL() . "</pre>";
//
// Select from database
//
$db->select("age, text, text1")->from('test')->where("id = 2");
echo "<pre>" . $db->getSQL() . "</pre>";
$db->orderBy("id ASC");
echo "<pre>" . $db->getSQL() . "</pre>";
//
// Select and join from database
//
$db->select("t1.*, t2.*")->from('test AS t1')->join('test AS t2', 't1.id = t2.id');
echo "<pre>" . $db->getSQL() . "</pre>";
$db->select("t1.*, t2.*, t3.*")->from('test AS t1')->join('test AS t2', 't1.id = t2.id')->join('test AS t3', 't1.id = t3.id');
echo "<pre>" . $db->getSQL() . "</pre>";
//
// Select, limit and offset
//
$db->select("*")->from('test')->limit('1');
echo "<pre>" . $db->getSQL() . "</pre>";
Пример #3
0
<?php

// Get environment & autoloader.
require __DIR__ . '/config.php';
$db = new \Mos\Database\CDatabaseBasic();
$options = (require "config_mysql.php");
$db->setOptions($options);
$db->connect();
$db->setVerbose();
// Set verbose mode to on
$db->select()->from('test')->orderBy("id ASC");
$db->execute();