2012-08-29 3 views
1

기본적으로 파일이 있는지 확인한 다음이 스크립트를 만듭니다. 내가 OOP가 아닌 버전을 사용했을 때 좋았습니다.OOP로 수정 된 스크립트가 작동하지 않습니다.

이제 OOP가 될 수 있도록 수정되었으며 어떻게 작동하지 않고 Apache에서 오류가 발생합니다. PHP 치명적 오류 : C : \ Program Files (x86) \ Zend \ Apache2에서 정의되지 않은 함수 createFile()을 호출하십시오. 라인 66 라인 //// THE ERROR LINE BELOW

무슨 잘못이와 함께입니다 \ htdocs를 \ Proj11 \ 1.php는 라인 (66)

에 내가 강조 ??? 들으

<?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 .= "<?php\n"; 
      $fString .= "// Database Constants\n"; 
      $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 
+0

참고로, 이것은 OOP가 아닙니다. –

답변

8

createFile() 클래스에 정의 된 방법이며, $this->createFile()로 클래스 내에서 호출해야합니다 나는 철저하게 아직 코드를 통해보고하지 않은

if ($this->createFile()) {...} 

,하지만 당신은 $this->를 생략했을 수 있습니다 다른 메소드 호출에서도 마찬가지입니다.

createFile()TRUE 이외의 값을 반환하는 상황이 전혀 나타나지 않으므로 if() {} 블록이 실제로 필요하지 않습니다. else 사례에는 절대 연락 할 수 없습니다.

관련 문제