Login   Register  
PHP Classes
elePHPant
Icontem

File: buildDatabaseConf.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Richard Munroe  >  SQL Data  >  buildDatabaseConf.php  >  Download  
File: buildDatabaseConf.php
Role: Application script
Content type: text/plain
Description: Builds a file containing MySQL access information
Class: SQL Data
Generate classes to store objects in SQL databases
Author: By
Last change: Reorganize the includes and switch the license over to the local standard.
Date: 8 years ago
Size: 1,937 bytes
 

Contents

Class file image Download
<?php
/**
 * @author Dick Munroe <munroe@csworks.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 munroe@csworks.com 03-May-2005
//      Initial Version Created
//
//  Dick Munroe munroe@csworks.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 
;
}


$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($theStreamsprintf('<?php

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

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

exit(
0) ;
?>