Ejemplo n.º 1
0
 @Override
 public void useDatabase(String alias, String path) {
   File f;
   try {
     f = FileWriterImpl.getInstace().fileCreate(path);
   } catch (IOException ex) {
     Logger.getLogger(PHPGenericWriterImpl.class.getName()).log(Level.SEVERE, null, ex);
     return;
   }
   // get database config
   DatabaseConfig db = DBManagerImpl.getInstace().getDatabaseConfig(alias);
   // include of connection details
   FileWriterImpl.getInstace().writeLine("include '" + db.getConfigFileName() + "';", f);
   // PDO connection to database
   String phpCode =
       "/* Connect to an ODBC database using driver invocation */\n"
           + "$_dsn = 'mysql:dbname=$_db_config_databaseName;host=$_db_config_host';\n"
           + "\n"
           + "try {\n"
           + "    $dbh = new PDO($_dsn, $_db_config_user, $_db_config_password);\n"
           + "} catch (PDOException $e) {\n"
           + "    echo 'Connection failed: ' . $e->getMessage();\n"
           + "}";
   FileWriterImpl.getInstace().writeLine(phpCode, f);
 }