Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <?php
  2. //DB Config File
  3.  
  4.  
  5.  
  6. $phase = $_GET['phase'];
  7.  
  8. if(empty ($phase)){
  9. $phase = new phase1();
  10. $phase->start();
  11. } elseif ($phase = 1) {
  12. $phase = new phase2();
  13. $phase->stepFunction();
  14. };
  15.  
  16. class phase1 {
  17.  
  18. function __construct () {
  19. $dbFile = 'dbconfig.php';
  20. $step = 0;
  21. $username = $_GET['username'];
  22. $password = $_GET['password'];
  23. $server = $_GET['server'];
  24. $dbName = $_GET['dbName'];
  25.  
  26. $this->step = $step;
  27. $this->dbFile = $dbFile;
  28. $this->username = $username;
  29. $this->password = $password;
  30. $this->server = $server;
  31. $this->dbName = $dbName;
  32.  
  33. $db = new PDO ('mysql:host=' .$server.';dbname='.$this->dbName,$this->username,$this->password);
  34.  
  35. $this->db = $db;
  36. }
  37.  
  38.  
  39. public function createFile () {
  40. //Creates File and populates it.
  41. $fOpen = fopen($this->dbFile, 'w');
  42. $fString .= "<?phpn";
  43. $fString .= "// Database Constantsn";
  44. $fString .= "$DB_SERVER =" . """ . $this->server . "";n";
  45. $fString .= "$DB_USER =" . """ . $this->username . "";n";
  46. $fString .= "$DB_PASS =" . """ . $this->password . "";n";
  47. $fString .= "$DB_NAME =". """ . $this->dbName . "";n";
  48. $fString .= "?>";
  49.  
  50. fwrite($fOpen, $fString);
  51. fclose($fOpen);
  52.  
  53. return true;
  54. }
  55.  
  56.  
  57. public function start (){
  58.  
  59. try {
  60.  
  61. if ($this->db) { //if succesful at connecting to the DB
  62.  
  63. if (file_exists($this->dbFile)){
  64. if (is_readable($this->dbFile) && is_writable($this->dbFile)){
  65.  
  66. //Creates File, populates it and redirects the user
  67.  
  68. //////////////////////////
  69. //// THE ERROR LINE BELOW
  70. //////////////////////////
  71.  
  72. if (createFile()) {
  73.  
  74. $phase = new phase2();
  75. $phase->stepFunction($this->step);
  76. exit ();
  77. }
  78.  
  79.  
  80. } else {
  81.  
  82. echo "The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission."; }
  83.  
  84. } else {
  85.  
  86. //Creates File, populates it and redirects the user
  87.  
  88. if (createFile()) {
  89.  
  90.  
  91. $phase = new phase2();
  92. $phase->stepFunction($this->step);
  93. exit ();
  94. }
  95.  
  96. }
  97.  
  98.  
  99. }
  100.  
  101. } catch (PDOException $e) { //Catchs error if can't connect to the db.
  102. echo 'Connection failed: ' . $e->getMessage();
  103. }
  104.  
  105. }
  106. } // en class Phase 1
  107.  
  108. if ($this->createFile()) {...}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement