Esempio n. 1
0
 public static function connect($host, $name, $prefix, $user, $password)
 {
     /* define the connection parameters */
     $dsn = 'mysql:host=' . $host . ';dbname=' . $name;
     try {
         /* inititate the connection */
         JxBotDB::$db = new PDO($dsn, $user, $password);
         if (JxBotDB::$db === false) {
             throw new Exception("Couldn't connect to database.");
         }
         /* ensure all further accesses throw an exception 
         			in the event of an error */
         JxBotDB::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         /* set character set */
         JxBotDB::$db->exec('SET NAMES utf8');
     } catch (Exception $err) {
         /* if anything goes wrong, return false */
         return false;
     }
     return true;
     /* successful connection! */
 }
Esempio n. 2
0
 public static function try_connect_db()
 {
     return JxBotDB::connect(JxBotConfig::option('db_host'), JxBotConfig::option('db_name'), JxBotConfig::option('db_prefix'), JxBotConfig::option('db_username'), JxBotConfig::option('db_password'));
 }