I need to create a new .php file as MySQL connection configuration file. I have a listing like this:
$fileLocation = $_SERVER['DOCUMENT_ROOT'] . "/dbconnect.php";
file_put_contents($fileLocation,$content);
$content = "<?php $koneksi = mysql_connect('.$host.', '.$username.', '.$password.'); //open connection
if(! $koneksi ) //if fail
{
die(\'Gagal Koneksi: \' . mysql_error());
}
echo \'Koneksi Berhasil\'; ?>";
I get the $username
, $host
, and $password
from another file (containing form for the host, username, and password) using post method.
And I want to create the file in the root directory, I did that code and it doesn't work. I try fwrite
and doesn't work too. I Google it but I'm not really understand what am I reading.
How should I do that?