Location: PHPKode > scripts > Php Installer > php-installer-1/setup/index.php
<?php
/*
Created by: Adam Patterson

This is a free aplication you can change what 
ever you like as long as you keep mention of my name. 

	Copyright (c) 2007, Adam Patterson
	http://www.adam-patterson.com | http://www.studiolounge.net
	Installer is released under the GPL license
	http://www.gnu.org/licenses/gpl.txt

This script is designed to let users create a config.php file used to connect 
to a MySQL DB and install the default MySQL into the DB.

*/

if (!is_writable('../')) die("Sorry, I can't write to the directory. You'll have to either change the permissions on your installation directory or create your config.php manually.");

if (isset($_GET['step']))
	$step = $_GET['step'];
else
	$step = 0;
header( 'Content-Type: text/html; charset=utf-8' );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Installer &rsaquo; Setup Configuration File</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style media="screen" type="text/css">
<!--
html {
	background: #eee;
}
body {
	background: #fff;
	color: #000;
	font-family: Geneva, Arial, Helvetica, sans-serif;
	margin-left: 20%;
	margin-right: 20%;
	padding: .2em 2em;
}
h1 {
	color: #000000;
	font-size: 36px;
	font-weight: lighter;
	font-family: Geneva, Arial, Helvetica, sans-serif;
	text-decoration: underline;
}
h2 {
	font-size: 16px;
}
p, li, dt {
	line-height: 140%;
	padding-bottom: 2px;
}
ul, ol {
	padding: 5px 5px 5px 20px;
}
.step a, .step input {
	font-size: 14px;
}
td input {
	font-size: 14px;
}
.step, th {
	text-align: right;
}
#fsubmit {
	width: 67px;
	height: 23px;
	border: none;
	text-indent: -900em;
	line-height: 0px;
	background-image: url(button-submit.png);
	background-repeat: no-repeat;
}
#fback {
	background: url(button-back.png) no-repeat;
	width: 53px;
	height: 23px;
	border: none;
	text-indent: -900em;
	line-height: 0px;
}
#footer {
	text-align: center;
	border-top: 1px solid #ccc;
	padding-top: 1em;
	font-style: italic;
}
-->
</style>
</head>
<body>
<h1>Installer</h1>
<?php
switch($step) {
	case 0:
// Check if config.php has been created
if (file_exists('../config.php'))
	die("<p>The file 'config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first.</p></body></html>");
?>
<p>Welcome to your install. Before getting started, we need some information on the database. You will need to know the following items before proceeding.</p>
<ol>
  <li>Database name</li>
  <li>Database username</li>
  <li>Database password</li>
  <li>Database host</li>
</ol>
<p><strong>If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open <code>config-sample.php</code> in a text editor, fill in your information, and save it as <code>config.php</code>. </strong></p>
<p>In all likelihood, these items were supplied to you by your Hosting Company. If you do not have this information, then you will need to contact them before you can continue. If you&#8217;re all ready, <a href="?step=1">let&#8217;s go</a>! </p>
<?php
	break;

	case 1:
	?>
</p>
<form method="post" action="?step=2">
  <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
  <table>
    <tr>
      <th scope="row">Database Name</th>
      <td><input name="dbname" type="text" size="25"/></td>
      <td>The name of the database you want to run your script in. </td>
    </tr>
    <tr>
      <th scope="row">User Name</th>
      <td><input name="uname" type="text" size="25"/></td>
      <td>Your MySQL username</td>
    </tr>
    <tr>
      <th scope="row">Password</th>
      <td><input name="pwd" type="text" size="25"/></td>
      <td>Your MySQL password.</td>
    </tr>
    <tr>
      <th scope="row">Database Host</th>
      <td><input name="dbhost" type="text" size="25" value="localhost" /></td>
      <td>Most Likely  won't need to change this value.</td>
    </tr>
  </table>
  <h2 class="step">
    <input name="submit" type="submit" id="fsubmit" value="Submit" />
  </h2>
</form>
<?php
	break;	
	case 2:
	$dbname  = trim($_POST['dbname']);
    $dbuser   = trim($_POST['uname']);
    $dbpwd = trim($_POST['pwd']);
    $host  = trim($_POST['dbhost']);

    // We'll fail here if the values are no good.
    require_once('../open-db.php');
	$handle = fopen('../config.php', 'w');
	
$source = array (
"<? \n",
"$","dbname = 'databasename';	// The name of the database \n",
"$","dbuser = 'username'; 	// MySQL username \n",		
"$","dbpwd = 'password';	// MySQL Password \n",	
"$","host = 'localhost';	// Most likely you wont need to change this \n",
"?>" );

$search = array ( databasename, username, password, localhost );
$replace = array ($dbname, $dbuser, $dbpwd, $host);

$source = str_replace ( $search, $replace, $source );
foreach ( $source as $str )
	fwrite($handle, $str);
?>
<p>All right everything is ready to roll!</p>
<a href="?step=3">let&#8217;s install  the MySQL</a>!
</p>
<?php
	break;
	case 3:
	
if (file_exists("../config.php")) {

    // Prefix the table names. These already have `backticks` around them!
    $db_schema = array();

/*
Insert your MySQL in the $db_schema[] array, simply cut and paste the 
$db_schema[] chunk leaving the opening " and closing ";

You can also put $variables in the MySQL and have the data carried over.
*/
 
$db_schema[] = "CREATE TABLE `test` (
  `id` int(4) NOT NULL auto_increment,
  `rowName` varchar(100) NOT NULL default '',
  PRIMARY KEY  (`id`)
 );";
  
require_once('../config.php');
require_once('../open-db.php');

      echo "<h3>Creating tables...</h3>";
      foreach($db_schema as $sql) {
       mysql_query($sql);
      }
      echo "<h3>Done!</h3>";
  }
	
	break;
}
?>
<p id="footer"><a href="http://www.mapleflow.com" target="_blank">Maple Flow</a> installer.</p>
</body>
</html>
Return current item: Php Installer