I'm creating some code that will generate a new page with a configuration class. I used heredoc like below. So I want to pass $_POST['hostname'] variables into the heredoc. I tried a lot of things, but no luck. How can I do it?
<?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 );
?>