Location: PHPKode > scripts > SQL Data > buildDatabaseConf.php
<?php
/**
 * @author Dick Munroe <hide@address.com>
 * @copyright copyright @ Dick Munroe, 2005
 * @license http://www.csworks.com/publications/ModifiedNetBSD.html
 */

//
// Build the configuration file for accessing a database.
//
//	$Author: munroe $
//	$Date: 2006/03/14 13:49:33 $
//
// Edit History:
//
//  Dick Munroe hide@address.com 03-May-2005
//      Initial Version Created
//
//  Dick Munroe hide@address.com 14-Mar-2006
//	Change licensing, reorganize includes.
//

if (count($_SERVER['argv']) < 4)
{
    print("
buildDatabaseConf databaseName hostName userName password

    Build the database configuration file of the form
    \"config.databaseName.php\" which is included by both
    the forms built by buildForm and the form processors
    built by buildProcessForm.
") ;
    return 0 ;
}


$theDatabaseName = $_SERVER['argv'][count($_SERVER['argv']) - 4] ;
$theHostName = $_SERVER['argv'][count($_SERVER['argv']) - 3] ;
$theUserName = $_SERVER['argv'][count($_SERVER['argv']) - 2] ;
$thePassword = $_SERVER['argv'][count($_SERVER['argv']) - 1] ;

//
// Preserve the outfile, if one already exists.
//

$theFileName = sprintf("config.%s.php", $theDatabaseName) ;
$theOldFileName = $theFileName . ".old" ;

if (file_exists($theFileName))
{
  if (is_file($theFileName))
    {
      if (!rename($theFileName, $theOldFileName))
	{
	  exit(1) ;
	}
    }
  else
    {
      exit(2) ;
    }
}

if (!($theStream = @fopen($theFileName, 'w')))
{
  exit(3) ;
}

fwrite($theStream, sprintf('<?php

//
// Configuration file for:
//
// Database: %s
//
// Generated by buildDatabaseConf.php, written by Dick Munroe (hide@address.com)
//

$the%sDatabase="%s" ;
$the%sHost="%s" ;
$the%sUser="%s" ;
$the%sPassword="%s" ;
?>
',	     		   $theDatabaseName, 
			   $theDatabaseName, $theDatabaseName,
			   $theDatabaseName, $theHostName,
			   $theDatabaseName, $theUserName,
			   $theDatabaseName, $thePassword)) ;

exit(0) ;
?>
Return current item: SQL Data