基本的に、ファイルが存在するかどうかを確認してから作成するこのスクリプトを作成しました。OOP 以外のバージョンを使用する前は、うまく機能していました。
OOPになるように変更しましたが、どういうわけか機能せず、Apache PHP Fatal error: Call to undefined function createFile() in C:\Program Files (x86)\Zend\Apache2\htdocs\Proj11\でエラーが発生します1.php 66行目
行 66 が行で強調表示されました//// THE ERROR LINE BELOW
どうしたの???どうも
<?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