public static function createFromConf($conf)
 {
     if (!isset($conf["user"]) or !isset($conf["password"])) {
         throw new ServiceException("INVALID_CONFIGURATION", "No MySQL db user information defined");
     }
     if (isset($conf["host"])) {
         $host = $conf["host"];
     } else {
         $host = "localhost";
     }
     if (isset($conf["database"])) {
         $database = $conf["database"];
     } else {
         $database = "kloudspeaker";
     }
     if (isset($conf["table_prefix"])) {
         $tablePrefix = $conf["table_prefix"];
     } else {
         $tablePrefix = "";
     }
     if (isset($conf["port"])) {
         $port = $conf["port"];
     } else {
         $port = NULL;
     }
     if (isset($conf["socket"])) {
         $socket = $conf["socket"];
         $port = NULL;
     } else {
         $socket = NULL;
     }
     if (isset($conf["engine"])) {
         $engine = $conf["engine"];
     } else {
         $engine = NULL;
     }
     $db = new MySQLIDatabase($host, $conf["user"], $conf["password"], $database, $tablePrefix, $port, $socket, $engine);
     $db->connect();
     if (isset($conf["charset"])) {
         $db->setCharset($conf["charset"]);
     }
     return $db;
 }
 public function createConnection($settings)
 {
     if (!$settings->hasSetting("db")) {
         throw new ServiceException("INVALID_CONFIGURATION", "No database settings defined");
     }
     $db = $settings->setting("db");
     if (!isset($db["type"])) {
         throw new ServiceException("INVALID_CONFIGURATION", "No database type defined");
     }
     $type = $db["type"];
     if (strcasecmp($type, 'pdo') == 0) {
         require_once "db/pdo/PDODatabase.class.php";
         return PDODatabase::createFromConf($db);
     } else {
         if (strcasecmp($type, 'mysql') == 0) {
             require_once "db/mysql/MySQLIDatabase.class.php";
             return MySQLIDatabase::createFromConf($db);
         } else {
             if (strcasecmp($type, 'postgresql') == 0) {
                 require_once "db/postgresql/PostgresqlDatabase.class.php";
                 return PostgresqlDatabase::createFromConf($db);
             } else {
                 if (strcasecmp($type, 'sqlite3') == 0) {
                     require_once "db/sqlite/SQLite3Database.class.php";
                     return KloudspeakerSQLite3Database::createFromConf($db);
                 } else {
                     if (strcasecmp($type, 'sqlite') == 0) {
                         require_once "db/sqlite/SQLiteDatabase.class.php";
                         return KloudspeakerSQLiteDatabase::createFromConf($db);
                     } else {
                         throw new ServiceException("INVALID_CONFIGURATION", "Unsupported database type: [" . $type . "]");
                     }
                 }
             }
         }
     }
 }
 public function init()
 {
     $this->db = MySQLIDatabase::createFromConf($this->settings["db"]);
     $this->db->connect(FALSE);
     $this->dbUtil = new DatabaseUtil($this->db);
 }