기본적으로 파일이 있는지 확인한 다음이 스크립트를 만듭니다. 내가 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
참고로, 이것은 OOP가 아닙니다. –