本文整理匯總了PHP中DBC::getConnection方法的典型用法代碼示例。如果您正苦於以下問題:PHP DBC::getConnection方法的具體用法?PHP DBC::getConnection怎麽用?PHP DBC::getConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DBC
的用法示例。
在下文中一共展示了DBC::getConnection方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: array
// EXIT_ERROR
}
//Depending on authentication method validate key-value pair
if (AUTH_TYPE === 'plain') {
$authorizer = array('user1' => '65h4g9874h65464h894hg65487h64', 'user2' => 'gfd46165fdh897yt6541616df7rer', 'user3' => 'gg8971646uo561dfh546d78te564r', 'user4' => 'uku55fh156456j3213gd1651af654');
if (strcmp($authorizer[$key], $value) !== 0) {
header('HTTP/1.1 401 Unauthorized.', TRUE, 401);
echo 'You are not authorised to access this page.';
exit(1);
// EXIT_ERROR
}
} elseif (AUTH_TYPE === 'db') {
require_once SYS_PATH . 'dbConfig.php';
$dbc = new DBC(0);
// 0 defines database id in dbConfig.php
$db = $dbc->getConnection();
$db->exec("SET CHARACTER SET utf8");
try {
$sql = "SELECT id FROM `users` WHERE `key`= ? AND `pass`= ?";
$stmt = $db->prepare($sql);
$stmt->execute(array($key, $value));
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$rows = $stmt->fetchAll();
if (empty($rows)) {
header('HTTP/1.1 401 Unauthorized.', TRUE, 401);
echo 'You are not authorised to access this page.';
exit(1);
// EXIT_ERROR
}
$dbc->closeConnection();
} catch (PDOException $e) {
示例2: DBC
function __construct()
{
$dbc = new DBC(0);
$this->db = $dbc->getConnection();
$this->db->exec("SET CHARACTER SET utf8");
}