Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //DB Config File
- $phase = $_GET['phase'];
- if(empty ($phase)){
- $phase = new phase1();
- $phase->start();
- } elseif ($phase = 1) {
- $phase = new phase2();
- $phase->stepFunction();
- };
- class phase1 {
- function __construct () {
- $dbFile = 'dbconfig.php';
- $step = 0;
- $username = $_GET['username'];
- $password = $_GET['password'];
- $server = $_GET['server'];
- $dbName = $_GET['dbName'];
- $this->step = $step;
- $this->dbFile = $dbFile;
- $this->username = $username;
- $this->password = $password;
- $this->server = $server;
- $this->dbName = $dbName;
- $db = new PDO ('mysql:host=' .$server.';dbname='.$this->dbName,$this->username,$this->password);
- $this->db = $db;
- }
- public function createFile () {
- //Creates File and populates it.
- $fOpen = fopen($this->dbFile, 'w');
- $fString .= "<?phpn";
- $fString .= "// Database Constantsn";
- $fString .= "$DB_SERVER =" . """ . $this->server . "";n";
- $fString .= "$DB_USER =" . """ . $this->username . "";n";
- $fString .= "$DB_PASS =" . """ . $this->password . "";n";
- $fString .= "$DB_NAME =". """ . $this->dbName . "";n";
- $fString .= "?>";
- fwrite($fOpen, $fString);
- fclose($fOpen);
- return true;
- }
- public function start (){
- try {
- if ($this->db) { //if succesful at connecting to the DB
- if (file_exists($this->dbFile)){
- if (is_readable($this->dbFile) && is_writable($this->dbFile)){
- //Creates File, populates it and redirects the user
- //////////////////////////
- //// THE ERROR LINE BELOW
- //////////////////////////
- if (createFile()) {
- $phase = new phase2();
- $phase->stepFunction($this->step);
- exit ();
- }
- } else {
- echo "The file {$dbFile} cannot be accessed. Please configure the file manualy or grant Write and Read permission."; }
- } else {
- //Creates File, populates it and redirects the user
- if (createFile()) {
- $phase = new phase2();
- $phase->stepFunction($this->step);
- exit ();
- }
- }
- }
- } catch (PDOException $e) { //Catchs error if can't connect to the db.
- echo 'Connection failed: ' . $e->getMessage();
- }
- }
- } // en class Phase 1
- if ($this->createFile()) {...}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement