本文整理汇总了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");
}