Esempio n. 1
0
 protected static function getConnection()
 {
     if (self::$db === null) {
         if (!self::$dsn) {
             throw new DJException("Please tell DJJob how to connect to your database by calling DJJob::configure(\$dsn) or re-using an existing PDO connection by calling DJJob::setConnection(\$pdoObject).");
         }
         try {
             self::$db = new PDO(self::$dsn);
             self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             throw new Exception("DJJob couldn't connect to the database. PDO said [{$e->getMessage()}]");
         }
     }
     return self::$db;
 }
Esempio n. 2
0
File: DJJob.php Progetto: qoqa/djjob
 protected static function getConnection()
 {
     if (self::$db === null) {
         if (!self::$dsn) {
             throw new DJException("Please tell DJJob how to connect to your database by calling DJJob::configure(\$dsn, [\$options = array()]) or re-using an existing PDO connection by calling DJJob::setConnection(\$pdoObject). If you're using MySQL you'll need to pass the db credentials as separate 'mysql_user' and 'mysql_pass' options. This is a PDO limitation, see [http://stackoverflow.com/questions/237367/why-is-php-pdo-dsn-a-different-format-for-mysql-versus-postgresql] for an explanation.");
         }
         try {
             // http://stackoverflow.com/questions/237367/why-is-php-pdo-dsn-a-different-format-for-mysql-versus-postgresql
             if (self::$options["mysql_user"] !== null) {
                 self::$db = new PDO(self::$dsn, self::$options["mysql_user"], self::$options["mysql_pass"]);
             } else {
                 self::$db = new PDO(self::$dsn);
             }
             self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         } catch (PDOException $e) {
             throw new Exception("DJJob couldn't connect to the database. PDO said [{$e->getMessage()}]");
         }
     }
     return self::$db;
 }
Esempio n. 3
0
 public static function runUpdate($sql, $params = array())
 {
     for ($attempts = 0; $attempts < self::$retries; $attempts++) {
         try {
             $stmt = self::getConnection()->prepare($sql);
             $stmt->execute($params);
             return $stmt->rowCount();
         } catch (PDOException $e) {
             // Catch "MySQL server has gone away" error.
             if ($e->errorInfo[1] == 2006) {
                 self::$db = null;
             } else {
                 throw $e;
             }
         }
     }
     throw new DJException("DJJob exhausted retries connecting to database");
 }