Location: PHPKode > scripts > SQLconf > sqlconf/install.php
  INSTALL.PHP                                             SQLconf v1.1
  -----------                                             ------------
  Copyright (C) 2003 by Max Timchenko    http://www.maxvt.com/sqlconf/
  Writing and reading configuration for your scripts has never been so 
  easy. Using MySQL as the backend and a minimal, automatically updated
  conf.php file, SQLconf provides a solution for all your configuration
* This file:
  - This file installs the SQLconf for use on your website.
* What does it do?
  - SQLconf requires a conf.php file accessible to it (in current
    directory) with MySQL access info, and the corresponding data in the
    DB in case conf.php needs to be rewritten. 
  - First, the script checks if conf.php file can be created,
    and asks for MySQL access info.
  - Then, the script checks the info and writes out the conf.php file,
    inserting the corresponding variables into the database.    
* License:
  - This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License (GPL)
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
  - This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.
  - To read the license please visit http://www.gnu.org/copyleft/gpl.html 

// Write the header
<html><body bgcolor="white">
<h1>SQLconf v1.0 Installation</h1>

// DB creation query
$db_query = <<<ENDQ
    module varchar(32) NOT NULL default '',
    name varchar(32) NOT NULL default '',
    value blob NOT NULL,
    exported tinyint(1) NOT NULL default '0',
    PRIMARY KEY  (module,name)
) TYPE=MyISAM COMMENT='This table stores the information for SQLconf.'

// If the form has been filled already...
if ($_GET['mode'] == 'do') {
    if (FALSE == @mysql_connect($_POST['host'], $_POST['user'], $_POST['pass'])) {
        print "<h2>Can't connect to MySQL database - check the values again!</h2>";
        unset($_GET['mode']); // return to form
    else // SQL connection established
    if (FALSE == @mysql_select_db($_POST['db'])) { 
        print "<h2>Can't select a database - check the 'database' value again!</h2>";
        unset($_GET['mode']); // return to form        
    else { // DB is ok, too -- create a table
        @mysql_query('DROP TABLE IF EXISTS conf');
        if (FALSE == @mysql_query($db_query)) { 
            print "<h2>Table creation failed! Does your user have CREATE and DROP rights for the database?</h2>";
            print mysql_error();
            unset($_GET['mode']); // return to form        
        else { 
            print "<p>Adding values to the table...";
            $query = "INSERT INTO conf VALUES('MySQL', 'Server', '{$_POST['host']}', 1)";
            $query = "INSERT INTO conf VALUES('MySQL', 'User', '{$_POST['user']}', 1)";
            $query = "INSERT INTO conf VALUES('MySQL', 'Pass', '{$_POST['pass']}', 1)";
            $query = "INSERT INTO conf VALUES('MySQL', 'DB', '{$_POST['db']}', 1)";
            print "OK</p>\n";
            print "<p>Creating environment for SQLconf...";
            define(MYSQL_SERVER, $_POST['host']);
            define(MYSQL_USER, $_POST['user']);
            define(MYSQL_PASS, $_POST['pass']);
            define(MYSQL_DB, $_POST['db']);
            print "OK</p>\n";
            print "<p>Creating empty CONF.PHP...";
            $f = fopen('conf.php', 'w');
            fwrite($f, "<?php ?".">");
            print "OK</p>\n";
            print "<p>Including SQLconf...";
            print "OK</p>\n";
            print "<p>Making a real CONF.PHP...";
            print "OK</p>\n";
            print "<h2>If all the lines above end with OK, the installation has been successful!<br>".
                  "Enjoy using SQLconf!</h2>";
            print "<p>For security considerations, you <b>must</b> delete install.php <b>now</b>.</p>";
            print "</body></html>";

// otherwise, first call : check if conf.php can be written
if (!isset($_GET['mode'])) {
    if (FALSE == ($f = @fopen('conf.php', 'w'))) {
        print "<h2>Can't write to conf.php file!</h2>";
    // ...and print the SQL data input form 
    <h2>Please enter the MySQL data below...</h2>
    <form method="POST" action="install.php?mode=do">
    <table border="0" cellpadding="5">
        <input type="text" name="host" length="30" maxlength="80" value="<?php echo $_POST['host']; ?>"></td></tr>
        <input type="text" name="user" length="30" maxlength="80" value="<?php echo $_POST['user']; ?>"></td></tr>
        <input type="password" name="pass" length="30" maxlength="80"></td></tr>
        <input type="text" name="db" length="30" maxlength="80" value="<?php echo $_POST['db']; ?>"></td></tr>
    </table><br><input type="submit" value="Proceed"></form></body></html>
Return current item: SQLconf