graham23s Posted March 29, 2010 Share Posted March 29, 2010 Hi Guys, A few people i give scripts to are having problems editing database files etc, so i was just going to write an install.php script for easiness. What would be the best way to do it? i have 4 fields host,user,pass,database fields i a form once its submitted write a config.php file with the values is that usually how its done? cheers guys Graham Quote Link to comment Share on other sites More sharing options...
Jax2 Posted March 30, 2010 Share Posted March 30, 2010 That's how I did it. In my install file, it asks the user for all the values, stores them as variables and then uses fwrite ... here's the code I use (Mind you, it's pretty ugly, but I wanted to keep things simple lol!! $dbfile = "../includes/db.php"; $fh = fopen($dbfile, "w") or die("Could not open file!"); fwrite($fh, "<?php\n"); fwrite($fh, "\$host = \"".$_POST['db_host']."\";\n") or die("Could not write to file"); fwrite($fh, "\$username = \"".$_POST['db_username']."\";\n") or die("Could not write to file"); fwrite($fh, "\$password = \"".$_POST['db_password']."\";\n") or die("Could not write to file"); fwrite($fh, "\$dbname = \"".$_POST['db_name']."\";\n") or die("Could not write to file"); fwrite($fh, "\$prefix = \"".$_POST['db_prefix']."\";\n") or die("Could not write to file"); fwrite($fh, "\$db=\"mysql_connect(\$host, \$username, \$password);\n"); fwrite($fh, "mysql_select_db(\$dbname,\$db);\n"); fwrite($fh, "?>\n"); fclose($fh); chmod("../includes/db.php",0640); What it's doing is basically creating the new file with all the information, or if the file already exists, it just overwrites it with the new info. After that, it chmod's the file to 640 to protect it. I've tested it out a whole bunch of times and it's always worked perfectly. Quote Link to comment Share on other sites More sharing options...
graham23s Posted March 30, 2010 Author Share Posted March 30, 2010 Hi Jax, Thanks for that mate it does the jobby hehe cheers Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.