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