Jump to content

Install Script


graham23s

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.