예제 #1
0
<?php

include 'config.php';
// need to set the database type for PDO factory
$ConfigArray['DBDSN']['phptype'] = 'mysql';
$db = new A_Db_Pdo($ConfigArray['DBDSN']);
$db->connect();
if (!$db->isError()) {
    $sql = "SELECT * FROM users";
    $result = $db->query($sql);
    if (!$db->isError()) {
        dump($result->fetch(), '__call: fetch(): ');
        $row = $result->fetchAll();
        dump($row, 'ROW: ');
    } else {
        echo 'connect ERROR: ' . $db->getErrorMsg();
    }
} else {
    echo 'connect ERROR: ' . $db->getErrorMsg();
}
예제 #2
0
$Config = new A_Config_Ini('config/example.ini', 'production');
$Config->loadFile();
// import base config array into config object
$Config->import($ConfigArray);
// set error reporting from config
ini_set('error_reporting', $Config->get('ERROR'));
// Create HTTP Request object
$Request = new A_Http_Request();
// Start Sessions
$Session = new A_Session();
//$Session->start();
$UserSession = new A_User_Session($Session);
// Dbh
$dbconfig = array('phptype' => $Config->get('phptype'), 'database' => $Config->get('database'), 'hostspec' => $Config->get('hostspec'), 'username' => $Config->get('username'), 'password' => $Config->get('password'), 'attr' => array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));
$Db = new A_Db_Pdo($dbconfig);
$Db->connect();
#$Db = new A_Db_MySQL($dbconfig);
// Create HTTP Response object and set default template and valuesS
$Response = new A_Http_Response();
$Response->setTemplate('mainlayout', 'module');
$Response->set('BASE', $ConfigArray['BASE']);
$Response->set('title', 'Default Title');
$Response->set('head', '');
$Response->set('maincontent', 'Default main content.');
$Response->set('user', $UserSession);
// Add common objects to registry
$Locator->set('Config', $Config);
$Locator->set('Request', $Request);
$Locator->set('Response', $Response);
$Locator->set('Session', $Session);
$Locator->set('UserSession', $UserSession);