I am still a noob to PHP, just started learning it.
I am trying to write a PHP that will install a DB and also write some lines in a file which is the global.inc.php .
But i have some problems.
Problem 1.
I take some variables and put values into them by using a form.
Then i want to write some lines in global.inc.php using these values.
This is how the result must be in the file:
Code: Select all
<?php
$glob['dbdatabase'] = 'mydb';
$glob['dbhost'] = 'localhost';
$glob['dbpassword'] = 'pswd';
$glob['dbprefix'] = 'data';
$glob['dbusername'] = admin';
$glob['installed'] = '1';
$glob['rootDir'] = 'http:\\localhost\site';
$glob['rootRel'] = '/cpplessons/';
$glob['ptyxiakiURL'] = 'http:\\localhost\site\';
?>This is the code i have written in order to produce these result using fwrite:
Code: Select all
$filename = 'includes/global.inc.php';
$somecontent = "'<?php'\n
'$glob'['dbdatabase'] = ''$database'';\n //$database="mydb";
'$glob'['dbhost'] = ''$host'';\n //$host="localhost";
'$glob'['dbpassword'] = ''$password'';\n //$password="pswd"; and so on...
'$glob'['dbprefix'] = 'data';\n //data is not a variable
'$glob'['dbusername'] = ''$username'';\n
'$glob'['installed'] = '1';\n
'$glob'['rootDir'] = ''$url'';\n
'$glob'['rootRel'] = '/'$relation'/';\n
'$glob'['ptyxiakiURL'] = ''$url\'';\n
'?>'" ;
if (is_writable($filename)) {
if (!$handler = fopen($filename, 'a')) {
echo "Cannot open file ($filename)\n";
exit;
}
if (fwrite($handler, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)\n";
exit;
}
echo "Succesfull write ($somecontent) to file ($filename)\n";
fclose($handler);
}
else {
echo "Cannot write to file!\n";
exit;
}The problem is i don't know how must i write things for $somecontent in order to take $glob as text and $database as variable and write to file the appropriate value. I think it's a prob with " and ' but i can't quite grasp it.
Can anyone tell me what is the right way to do that in order to get the result i posted on top?
Thanks in advance.