我正在创建一些代码,这些代码将生成一个带有配置类的新页面。我像下面这样使用了heredoc 。所以我想将 $_POST['hostname'] 变量传递到heredoc。我尝试了很多东西,但没有运气。我该怎么做?
<?php
if(isset($_POST['hostname'])) {
$HOSTNAME = $_POST['hostname'];
}
if(isset($_POST['database'])) {
$DATABASE = $_POST['database'];
}
if(isset($_POST['dbuser'])) {
$USER = $_POST['dbuser'];
}
if(isset($_POST['dbuserpassword'])) {
$PASSWORD = $_POST['dbuserpassword'];
}
$pardConfig = new PDO('mysql:host='.$HOSTNAME.';'.'dbname='.$DATABASE, $USER, $PASSWORD, array(
PDO::ATTR_PERSISTENT => true
));
if(isset($pardConfig)) {
echo "connected";
}
$SQL =<<<'EOD'
CREATE TABLE IF NOT EXISTS pard_host (
host varchar(255) NOT NULL,
db varchar(255),
db_user varchar(255) NOT NULL,
db_pass varchar(255)
)
EOD;
$sq = $pardConfig->query($SQL);
if ($sq) {
echo 'created';
}
$stmt = $pardConfig->prepare("INSERT INTO pard_host (host, db, db_user, db_pass) VALUES (?, ?, ?, ?)");
$stmt->bindParam(1, $HOSTNAME);
$stmt->bindParam(2, $DATABASE);
$stmt->bindParam(3, $USER);
$stmt->bindParam(4, $PASSWORD);
$stmt->execute();
$PARD_CONFIGURATION_CLASS = <<<'EOT'
class pardConfig {
public $HOSTNAME = echo $DATABASE;;
public $DATABASE = echo $DATABASE;
public $USER = echo $USER;
public $PASSWORD = echo $PASSWORD;
}
EOT;
$PARD_FILE_OPEN = fopen("configuration.php", "w+");
fwrite($PARD_FILE_OPEN,$PARD_CONFIGURATION_CLASS );
?>