本文整理匯總了PHP中utility::connectToDB方法的典型用法代碼示例。如果您正苦於以下問題:PHP utility::connectToDB方法的具體用法?PHP utility::connectToDB怎麽用?PHP utility::connectToDB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類utility
的用法示例。
在下文中一共展示了utility::connectToDB方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getByOwner
public function getByOwner($ownerID)
{
$DBH = utility::connectToDB();
if ($DBH == \NULL) {
return \NULL;
}
$sql = "\n\t\t\t\t SELECT \n\t\t\t\t\t * \n\t\t\t\t FROM \n\t\t\t\t items\n\t\t\t\t WHERE \n\t\t\t\t\t owner = :id\n\t\t\t\t ";
try {
$STH = $DBH->prepare($sql);
$STH->bindParam(':id', $ownerID);
if ($STH->execute()) {
$results = $STH->fetchAll();
} else {
echo 'Error: retreaving data\\n';
print_r($DBH->errorInfo());
print_r($STH->errorInfo());
return \NULL;
}
$count = $STH->rowCount();
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage();
$DBH = \NULL;
return \NULL;
}
$DBH = \NULL;
return Items::newCollection($results, $count);
}
示例2: logEvent
private function logEvent($eventCatagory, $loanID, $itemID)
{
$timeNow = date('Y-m-d H:i:s');
$DBH = utility::connectToDB();
if ($DBH == \NULL) {
echo "Error connecting to database";
exit;
}
$sql = "\n\t\t\t\tINSERT INTO eventLog \n\t\t\t\t\t ( \n\t\t\t\t\t\t FK_ITEM_ID,\n\t\t\t\t\t\t FK_LOAN_ID,\n\t\t\t\t\t\t event,\n\t\t\t\t\t\t eventDate\n\t\t\t\t\t )\n\t\t\t\t VALUES\n\t\t\t\t\t (\n\t\t\t\t\t\t :id,\n\t\t\t\t\t\t :loanID,\n\t\t\t\t\t\t :event,\n\t\t\t\t\t\t :eventDate\n\t\t\t\t\t )\n\t\t\t\t";
try {
$STH = $DBH->prepare($sql);
$STH->bindParam(':id', $itemID);
$STH->bindParam(':loanID', $loanID);
$STH->bindParam(':event', $eventCatagory);
$STH->bindParam(':eventDate', $timeNow);
$DBH->beginTransaction();
$sqlError = $STH->execute();
if (!$sqlError) {
echo 'Error: updating event log data';
print_r($DBH->errorInfo());
echo "<p>";
print_r($STH->errorInfo());
exit;
}
$DBH->commit();
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage();
$DBH = \NULL;
return \FALSE;
}
$DBH = \NULL;
return \TRUE;
}
示例3: getHistory
public function getHistory()
{
$DBH = utility::connectToDB();
if ($DBH == \NULL) {
echo "Error connecting to database";
exit;
}
$sql = "\n\t\t\t\tSELECT \n\t\t\t\t\t * \n\t\t\t\tFROM \n\t\t\t\t eventLog\n\t\t\t\tWHERE \n\t\t\t\t\tFK_ITEM_ID = :id\n\t\t\t\t";
try {
$STH = $DBH->prepare($sql);
$STH->bindParam(':id', $this->id);
if ($STH->execute()) {
$results = $STH->fetchAll();
} else {
echo 'Error: retreaving data\\n';
print_r($DBH->errorInfo());
print_r($STH->errorInfo());
}
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage();
$DBH = \NULL;
return \NULL;
}
$DBH = \NULL;
return $results;
}