Scalr::getDb PHP Method

getDb() public static method

Gets an ADO Database Connection as singleton
public static getDb ( boolean $forceNewConnection = null ) : ADODB_mysqli
$forceNewConnection boolean optional Force new connection. (false by default)
return ADODB_mysqli
    public static function getDb($forceNewConnection = null)
    {
        return Container::getInstance()->adodb($forceNewConnection);
    }

Usage Example

Esempio n. 1
0
 public function __call($method, $args)
 {
     // If observer enabled
     if (!$this->Config || $this->Config->GetFieldByName("IsEnabled")->Value == 0) {
         return;
     }
     $enabled = $this->Config->GetFieldByName("{$method}Notify");
     if (!$enabled || $enabled->Value == 0) {
         return;
     }
     $DB = \Scalr::getDb();
     // Event name
     $name = substr($method, 2);
     // Event message
     $message = $DB->GetOne("SELECT message FROM events WHERE event_id = ? LIMIT 1", array($args[0]->GetEventID()));
     $farm_name = $DB->GetOne("SELECT name FROM farms WHERE id=? LIMIT 1", array($args[0]->GetFarmID()));
     // Set subject
     if (!$farm_name) {
         $this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()})");
     } else {
         $this->Mailer->setSubject("{$name} event notification (FarmID: {$args[0]->GetFarmID()} FarmName: {$farm_name})");
     }
     // Set body
     $this->Mailer->setMessage($message);
     // Send mail
     try {
         $res = $this->Mailer->send();
     } catch (\Exception $e) {
         $res = false;
     }
     if (!$res) {
         Logger::getLogger(__CLASS__)->info("Mail sent to '{$this->Config->GetFieldByName("EventMailTo")->Value}'. Result: {$res}");
     }
 }
All Usage Examples Of Scalr::getDb