Reputation: 17
I am trying to create a php file with the fopen() function. The content of the php file(s) that will be created need to be built so that they can be executed at a later date to update a mysql db. So if the php file is created, it should show include to a config.php and a way to connect to the db and execute a query.
So for example, the file that will be created will look something like:
<?php
include_once 'config.php';
$updateSQL = "update table set is_active = 1 where id = 10";
$conn = mysqli_connect("$dbhost","$dbuser","$dbpass","$usedb");
if(! $conn )
{
die('Could not connect: ' . mysqli_error());
} else {
mysqli_query($conn,$updateSQL );
}
?>
Creating an empty php file is simple but I don't know whether it is possible to show variables in the file that will be created. FYI, the file will consist of other tasks such as creating a directory which I can do, this is the part I am stuck on so any suggestions?
Upvotes: 0
Views: 112
Reputation: 470
this my solve your query
<?php
$text = "hi Amar";
$var_str = var_export($text, true);
echo $var = "\n\n\$text = $var_str;\n\n";
?>
Result: $text = 'hi Amar';
Upvotes: 1