Location: PHPKode > scripts > My One Line SQL > my-one-line-sql/DBconnect.class.php
<?php
/**
 * @package myOneLineSQL
 */
/**
 * Inclusion of variables for database connection
 */
include_once 'cvars.inc.php';
/**
 * DBconnect class
 *
 * Provides static method to start mySQL DB connections. This class cannot be instantiated.
 * 
 * This class uses constants defined in your configuration file which should be
 * normally located one directory above public_html
 * 
 * If no connection to database could be made, execution will stop
 * @package myOneLineSQL
 * @author Carlo Tasca
 * @version 1.0
 * 
 *
 */
class DBconnect
{
   /**
    * Class cannot have instances
    * 
    * @access private
    *
    */
   private function __construct()
   {
      trigger_error ( "Class DBconnect cannot be instantiated", E_USER_ERROR );
   }
   /**
    * DoDBConnection()
    * 
    * Defines database connection or die if connection is not achieved.
    * Constants for connection must have been given proper values in
    * configuration file in order to connect successfully.
    *
    */
   public static function doDBConnection()
   {
      $dbConnection = mysql_connect ( DBHOST, DBCLIENT, DBPASS );
      if (! $dbConnection)
      {
         die ( mysql_error ( "CANNOT CONNECT TO DATABASE" ) );
      }
      if (! (mysql_select_db ( DBNAME, $dbConnection )))
      {
         die ( mysql_error ( "NO DATABASE SELECTED" ) );
      }
      /**
       * Defines Database Connection
       */
      define ( "DBC", $dbConnection );
   }
}
?>
Return current item: My One Line SQL