I was wondering how to make a install script that will ask for the mysql host , username, password, and database name (if not one it makes one) and will add the tables to database and will set the stuff up like say the site name and other stuff can someone show me how i can make a script like that?
Thank you
Smackie
i want something like this page here
http://www.hauntedgraveyard.net/logdnew ... c=5-142439
*Install Question*
Moderator: General Moderators
EXAMPLE.. ENJOY !
Code: Select all
<?
if ($step=="") {
$step=1;
}
if ($step==1) {
echo '<table width="549" bgcolor="#E5E5E5" cellpadding="3" cellspacing="0" border="0" height="100" align="center"><tr>';
echo '<td width="100%" align="center" height="100">';
echo '<p>THIS WILL WRITE YOU A NICE DB FILE.. MAKE NECESARY CHANGES !.</p>';
echo '</td></tr></table>';
echo "<p><center><a href=\"install.php?step=".($step+1)."\"><b>Continue --></b></a></center></p>\n";
} // end step 1
if ($step==2) {
$canwrite=@fopen($_SERVER['DOCUMENT_ROOT']."/PATH**/TO**/db.php","a");
@fclose($canwrite);
$canread=@fopen($_SERVER['DOCUMENT_ROOT']."/PATH**/TO**/db.php","r");
@fclose($canread);
$fileexists=file_exists($_SERVER['DOCUMENT_ROOT']."/PATH**/TO**/db.php");
if ($canwrite==0 and !$fileexists) {
// file does not exist and cannot write new file
echo "<p>Cannot find db.php file and cannot create new one automatically.</p>";
echo "<p>Make sure that you have uploaded it and that it is in the admin directory. It should look something like this:</p>";
?>
<pre>
<?php
#############################################################
### HERE YOU GO THIS WILL WRITE YOUR FILE #####
#############################################################
$dbservertype="mysql";
$servername="localhost";
$dbusername="root";
$dbpassword="";
$dbname="forum";
$technicalemail = "dbmaster@your-email-address-here.com";
\$link = @mysql_connect(\$servername, \$dbusername, \$dbpassword)
or die (mysql_error());
\$dbconnect = @mysql_select_db(\$dbname, \$link)
or die (mysql_error());
?></pre>
<?php
echo "<p>Make sure that when you upload the db.php file that there is no spaces before or after the <? ?></p>";
echo "<p>Once you have uploaded the new db.php file, reload this page.</p>";
exit;
}
if ($canwrite==0 and $fileexists) {
// test out config
include($_SERVER['DOCUMENT_ROOT']."/PATH**/TO**/db.php");
echo "<p>Please confirm the details below:</p>\n";
echo "<p><b>Database server type:</b> $dbservertype</p>\n";
echo "<p><b>Database server hostname / IP address:</b> $servername</p>\n";
echo "<p><b>Database username:</b> $dbusername</p>\n";
echo "<p><b>Database password:</b> $dbpassword</p>\n";
echo "<p><b>Database name:</b> $dbname</p>\n";
echo "<p><b>Technical email:</b> <a href=\"mailto:$technicalemail\">$technicalemail</a></p>\n";
echo "<p>Only continue to the next step if those details are correct. If they are not, please edit your db.php file and reupload it. The next step will test database connectivity.</p>";
if ($technicalemail=="dbmaster@your-email-address-here.com") {
echo "<p>Please update your 'Technical email' in your db.php before continuing.</p>";
} else {
echo "<p><a href=\"install.php?step=".($step+1)."\">Next step --></a></p>\n";
}
}
if ($canwrite!=0 and $fileexists) {
// test out config
include($_SERVER['DOCUMENT_ROOT']."/PATH**/TO**/db.php");
echo "<form action=\"install.php\" method=\"post\"><input type=hidden name=step value=writeconfig>";
echo "<p>Please confirm the details below:</p>\n";
echo "<p><b>Database server type:</b> <input name=\"dbservertype\" value=\"mysql\"></p>\n";
echo "<p><b>Database server hostname / IP address:</b> <input name=\"servername\" value=\"$servername\"></p>\n";
echo "<p><b>Database username:</b> <input name=\"dbusername\" value=\"$dbusername\"></p>\n";
echo "<p><b>Database password:</b> <input name=\"dbpassword\" value=\"$dbpassword\"></p>\n";
echo "<p><b>Database name:</b> <input name=\"dbname\" value=\"$dbname\"></p>\n";
echo "<p><b>Technical email:</b> <input name=\"technicalemail\" value=\"$technicalemail\"></a></p>\n";
echo "<p><input type=submit value=\"Update db.php file\"></form></p>";
if ($technicalemail!="dbmaster@your-email-address-here.com") {
echo "<p><form action=\"install.php\" method=get><input type=hidden name=step value=".($step+1)."><input type=submit value=\"Continue without updating values\"></form></p>\n";
}
}
if ($canwrite!=0 and !$fileexists) {
echo "<form action=\"install.php\" method=\"post\"><input type=hidden name=step value=writeconfig>";
echo "<p>Please confirm the details below:</p>\n";
echo "<p><b>Database server type:</b> <input name=\"dbservertype\" value=\"mysql\"></p>\n";
echo "<p><b>Database server hostname / IP address:</b> <input name=\"servername\" value=\"localhost\"></p>\n";
echo "<p><b>Database username:</b> <input name=\"dbusername\" value=\"root\"></p>\n";
echo "<p><b>Database password:</b> <input name=\"dbpassword\" value=\"\"></p>\n";
echo "<p><b>Database name:</b> <input name=\"dbname\" value=\"forum\"></p>\n";
echo "<p><b>Technical email:</b> <input name=\"technicalemail\" value=\"dbmaster@your-email-address-here.com\"></a></p>\n";
echo "<p><input type=submit value=\"Update db.php file\"></form></p>";
}
} // end step 2
if ($step=="writeconfig") {
$dbservertype = strtolower($dbservertype);
//write config file
if ($technicalemail=="dbmaster@your-email-address-here.com") {
echo "<P>Please enter a new email address in the technical email field.</p>";
exit;
}
$configfile="<"."?php
#############################################################
### HERE YOU GO THIS WILL WRITE YOUR FILE #####
#############################################################
// type of database running
// (only mysql is supported at the moment)
\$dbservertype='$dbservertype';
// hostname or ip of server
\$servername='$servername';
// username and password to log onto db server
\$dbusername='$dbusername';
\$dbpassword='$dbpassword';
// name of database
\$dbname='$dbname';
// technical email address - any error messages will be emailed here
\$technicalemail='$technicalemail';
\$link = @mysql_connect(\$servername, \$dbusername, \$dbpassword)
or die (mysql_error());
\$dbconnect = @mysql_select_db(\$dbname, \$link)
or die (mysql_error());
?".">";
if (file_exists($path)!=0) {
unlink($path);
}
$filenum=fopen($_SERVER['DOCUMENT_ROOT']."/PATH**/TO**/db.php","w");
fwrite($filenum,$configfile);
fclose($filenum);
}
?>