예제 #1
0
// Load application config data
$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);
예제 #2
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();
}
<?php

ini_set('date.timezone', 'America/Los_Angeles');
include 'config.php';
// need to set the database type for PDO factory
$ConfigArray['DBDSN']['phptype'] = 'mysql';
//include 'A/Db/Pdo.php';
include 'A/Db/Tabledatagateway.php';
class Projects extends A_Db_Tabledatagateway
{
}
$db = new A_Db_Pdo($ConfigArray['DBDSN']);
$db->connect();
if ($db->isError()) {
    die('ERROR: ' . $db->getMessage());
}
$project = new Projects($db, 'users');
$rows = $project->find(1);
dump($project->sql);
dump($rows);
// Get the current row
dump($rows->current());
// Get all rows
$all = $rows->fetchAll();
dump($all);
// Update some data
$data = array('lastname' => 'testert');
$updated = $project->update($data, 'id = 1');
//dump($updated);
$rows = $project->find(1);
dump($rows->current());