Example #1
0
 public static function get_connection($dsn, $db_user, $db_pass)
 {
     if (self::$connected == true) {
         return self::$connection;
     }
     try {
         self::$connection = new PDO($dsn, $db_user, $db_pass, array(PDO::ATTR_PERSISTENT => false));
     } catch (PDOException $e) {
         self::freichat_debug("unable to connect to database. Error : " . $e->getMessage());
         //die(); //do not die
         return false;
         //instead return false
     }
     self::freichat_debug("connected to database successfully");
     self::$connection->exec("SET CHARACTER SET utf8");
     self::$connection->exec("SET NAMES utf8");
     self::$connected = true;
     return self::$connection;
 }