基本的に私の問題は次の問題です...次のスクリプトはDBを接続し、ファイルを作成します....すべてが正常に機能します..ファイルにデータを入力するときを除いて..変数$username
、、、$password
を入れませんファイル。作成されたファイルは次のようになります$server
$dbname
<?php
// Database Constants
$DB_SERVER ="";
$DB_USER ="";
$DB_PASS ="";
$DB_NAME ="";
?>
しかし、引用符の中に何かがあるはずです:S
私のスクリプトは次のとおりです
<?php
//DB Config File
$dbFile = 'dbconfig.php';
function createfile ($dbFile) {
//Creates File and populates it.
$fOpen = fopen($dbFile, 'w');
$fString .= "<?php\n";
$fString .= "// Database Constants\n";
$fString .= "\$DB_SERVER =" . "\"" . $server . "\";\n";
$fString .= "\$DB_USER =" . "\"" . $username . "\";\n";
$fString .= "\$DB_PASS =" . "\"" . $password . "\";\n";
$fString .= "\$DB_NAME =". "\"" . $dbname . "\";\n";
$fString .= "?>";
fwrite($fOpen, $fString);
fclose($fOpen);
return true;
}
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$server = $_POST['server'];
$dbname = $_POST['dbname'];
try {
$db = new PDO ('mysql:host=' .$server.';dbname='.$dbname,$username,$password);
if ($db) { //if succesful at connecting to the DB
if (file_exists($dbFile)){
if (is_readable($dbFile) && is_writable($dbFile)){
//Creates File, populates it and redirects the user
if (createfile($dbFile)) {
header("Location: http://http://localhost/proj11/install2.php");
exit ();
}
} else {
$msg = "2The 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($dbFile)) {
header("Location: http://http://localhost/proj11/install2.php");
exit ();
}
}
}
} catch (PDOException $e) { //Catchs error if can't connect to the db.
$msg = 'Connection failed: ' . $e->getMessage();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="iForm" method="post" action="install.php">
<label id="username" >Username</label>
<input id="username" name="username"/>
<label id="password">Password</label>
<input id="password" name="password" />
<label id="server" >Server</label>
<input id="server" name="server"/>
<label id="dbName" >dbName</label>
<input id="dbName" name="dbname"/>
<input type="submit" name="submit" value="submit" />
</form>
<p id="error"><?php echo $msg ?></p>
</body>
</html>