<?php
define('SQL_FILE\',\'sql.sql\'); //file where CREATE TABLE querys are written
define(\'DB_FILE\',\'db.php\'); //new file where the database connection functions will be written to
//////////////////////////////////////////
//// do not edit beneath this line! ///
//////////////////////////////////////////
if(!IsSet($_GET[\'send\']))
{
//print form
?>
<style>
label {
display: block;
}
</style>
<title>Webscripters.be</title>
<h1>Install database</h1>
<p>Welcome to the installation of your MySQL database. Please follow the next steps for a safe and easy configuration.</p>
<form method=\"post\" action=\"?send\">
<label for=\"user\">Username:</label> <input name=\"user\" id=\"user\" type=\"text\" value=\"\">
<label for=\"password\">Password:</label> <input name=\"password\" id=\"password\" type=\"text\" value=\"\">
<label for=\"host\">Host:</label> <input name=\"host\" id=\"host\" type=\"text\" value=\"localhost\">
<label for=\"database\">Databasename:</label> <input name=\"database\" id=\"database\" type=\"text\" value=\"Name\">
<br>
<label for=\"permanent\" style=\"display: inline;\">Permanent databaseconnection:</label> <input type=\"checkbox\" name=\"permanent\" id=\"permanent\" value=\"true\">
<br><br>
<input type=\"submit\" value=\"Install\">
</form>
<?php
}
else
{
@mysql_connect($_POST[\'host\'],$_POST[\'user\'], $_POST[\'password\']) or ($ErrorCode = mysql_errno());
if(IsSet($ErrorCode))//connection failed
{
echo \'<h1>Database connection error</h1>\';
if($ErrorCode == 1045)
echo \'<p>Wrong username / password. Please try again.</p>\';
elseif($ErrorCode == 2005)
echo \'<p>Wrong host selected. Please try again.</p>\';
else
echo \'<p>Unknown error. Try again, and if this error continues, contact the developer of this software.</p>\';
echo \'<p><a href=\"\'. $_SERVER[\'PHP_SELF\'] .\'\">Back</a></p>\';
}
else
{
mysql_query(\'CREATE DATABASE IF NOT EXISTS \'.$_POST[\'database\']);
mysql_select_db($_POST[\'database\']);
@mysql_query(\"START TRANSACTION;\");//open transaction (see mysql.com)
$querys = @file_get_contents(SQL_FILE);
if(empty($querys))
die (\'<p>SQL file is empty or doesn\\\'t exists. Try again, and when this problem continues, contact the developer of this software.</p>\');
@mysql_query($querys) OR ($errors[] = mysql_error());
if(IsSet($errors))
{
echo \'<h1>Corrupted SQL file</h1>\';
echo \'<p>The used SQL file for inserting al the application databasetables, seems to containts wrong SQL lines. Your database couldn\\\'t be installed correctly. If this problem continues, contact the developer of this software.<br>Next errorlines where returned by MySQL:</p>\';
echo \'<ul>\';
foreach($errors AS $error)
echo \'<li>\'. $error .\'</li>\';
echo \'</ul>\';
@mysql_query(\'ROLLBACK;\');//deny querys
}
else
{
@mysql_query(\'COMMIT;\');//complete querys
if(IsSet($_POST[\'permanent\']))
$functie = \'mysql_pconnect\';
else
$functie = \'mysql_connect\';
$DbFile = \"<?php\". $functie . \"(\'\". strtolower($_POST[\'host\']) .\"\',\'\". $_POST[\'user\'] .\"\',\'\". $_POST[\'password\'] .\"\') or die(mysql_error()); \\nmysql_select_db(\'\". strtolower($_POST[\'database\']) .\"\') or die(mysql_error());?>\";
$fp = fopen(DB_FILE,\"w\");//make new file, deleted old file when exists
fwrite($fp,$DbFile);
fclose($fp);
echo \'<h1>Database succesfully installed</h1>\';
echo \'<p>The database is completly installed and configured. You can now use your PHP-application. Reload <a href=\"\'. $_SERVER[\'PHP_SELF\'] .\'?\'. $_SERVER[\'QUERY_STRING\'] .\'\">this page</a> to begin.</p>\';
}
}
}
?> |