Beispiel #1
0
<?php

require_once "../MysqliDb.php";
error_reporting(E_ALL);
$prefix = 't_';
$db = new Mysqlidb('localhost', 'root', '', 'testdb');
if (!$db) {
    die("Database error");
}
$mysqli = new mysqli('localhost', 'root', '', 'testdb');
$db = new Mysqlidb($mysqli);
$db = new Mysqlidb(array('host' => 'localhost', 'username' => 'root', 'password' => '', 'db' => 'testdb', 'prefix' => $prefix, 'charset' => null));
if (!$db) {
    die("Database error");
}
$db->setTrace(true);
$tables = array('users' => array('login' => 'char(10) not null', 'active' => 'bool default 0', 'customerId' => 'int(10) not null', 'firstName' => 'char(10) not null', 'lastName' => 'char(10)', 'password' => 'text not null', 'createdAt' => 'datetime', 'updatedAt' => 'datetime', 'expires' => 'datetime', 'loginCount' => 'int(10) default 0', 'unique key' => 'login (login)'), 'products' => array('customerId' => 'int(10) not null', 'userId' => 'int(10) not null', 'productName' => 'char(50)'));
$data = array('users' => array(array('login' => 'user1', 'customerId' => 10, 'firstName' => 'John', 'lastName' => 'Doe', 'password' => $db->func('SHA1(?)', array("secretpassword+salt")), 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc()), array('login' => 'user2', 'customerId' => 10, 'firstName' => 'Mike', 'lastName' => NULL, 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(2)), array('login' => 'user3', 'active' => true, 'customerId' => 11, 'firstName' => 'Pete', 'lastName' => 'D', 'password' => $db->func('SHA1(?)', array("secretpassword2+salt")), 'createdAt' => $db->now(), 'updatedAt' => $db->now(), 'expires' => $db->now('+1Y'), 'loginCount' => $db->inc(3))), 'products' => array(array('customerId' => 1, 'userId' => 1, 'productName' => 'product1'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product2'), array('customerId' => 1, 'userId' => 1, 'productName' => 'product3'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product4'), array('customerId' => 1, 'userId' => 2, 'productName' => 'product5')));
function createTable($name, $data)
{
    global $db;
    //$q = "CREATE TABLE $name (id INT(9) UNSIGNED PRIMARY KEY NOT NULL";
    $db->rawQuery("DROP TABLE IF EXISTS {$name}");
    $q = "CREATE TABLE {$name} (id INT(9) UNSIGNED PRIMARY KEY AUTO_INCREMENT";
    foreach ($data as $k => $v) {
        $q .= ", {$k} {$v}";
    }
    $q .= ")";
    $db->rawQuery($q);
}
// rawQuery test