當前位置: 首頁>>代碼示例>>PHP>>正文


PHP utility::connectToDB方法代碼示例

本文整理匯總了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);
 }
開發者ID:JLBR,項目名稱:School-Projects,代碼行數:27,代碼來源:items.class.php

示例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;
 }
開發者ID:JLBR,項目名稱:School-Projects,代碼行數:33,代碼來源:eventlog.class.php

示例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;
 }
開發者ID:JLBR,項目名稱:School-Projects,代碼行數:26,代碼來源:item.class.php


注:本文中的utility::connectToDB方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。