PHP Classes

File: class.MySQL_Connect.php

Recommend this page to a friend!
  Classes of Lee J   Ads and content limit   class.MySQL_Connect.php   Download  
File: class.MySQL_Connect.php
Role: Application script
Content type: text/plain
Description: Mysql connection
Class: Ads and content limit
Keeps track of visitors to show limited ads a day
Author: By
Last change:
Date: 13 years ago
Size: 2,892 bytes
 

Contents

Class file image Download
<?php
/*

name: class.MySQL_Connect.php
description: Check and Connect to MySQL database.
release date: 28-12-08
updated: 11-02-13
site: http://freakcms.com
Maker: lee johnstone
Support: info@freakcms.com

--------------------------------------------------------------------------------------------------------------------------
                                                LICENSE INFORMATION
--------------------------------------------------------------------------------------------------------------------------
YOU MAY NOT
1. Use this for commercial usage
2. Claim the code as your own
3. Remove any copyrights from its original authors

YOU MAY

1. Upgrade, Update, Adjust, Modify this script, providing you keep all original comments.
2. Redistribute this code under the same license and none other.
3. Modify and use this script on your own site as you wish, providing you keep the copyright markings from original authors.

More information here.
http://www.freakcms.com/licensing.php

--------------------------------------------------------------------------------------------------------------------------

*/

//////////////////////////////////////////////////////////
// START OF SQL CLASS //
//////////////////////////////////////////////////////////

class MySql_Con {
   
protected
$g_link = false;
//////////////////////////////////////////////////////////
// PROTECTED FUNCTIONS //
//////////////////////////////////////////////////////////
/**
 * CheckSql function
 * @desc Check's for an open connection and sets the link false if found
 */
protected function CheckSql(){
if (
$this->g_link) { // if the connections link is open
  
$this->CleanUpDB(); // We call the Cleanup function and close the connection.
   
}
    return;
}
//////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS //
//////////////////////////////////////////////////////////
/**
 * GetMyConnection function
 * @desc Opens a new MySQL Connection
 * @param $host
 * @param $user
 * @param $passwrd
 * @param $db
 * @return $g_link
 */
public function GetMyConnection($host="", $user="", $password="", $db=""){
   
$this->CheckSql();
   
$this->g_link = mysql_connect($host, $user, $password) or die('Could not connect to mysql server. ERROR: '.mysql_error() );
   
mysql_select_db($db, $this->g_link) or die('Could not select database. ERROR: '.mysql_error() );
    return
$this->g_link;
}
/**
 * CleanUpDB function
 * @desc Shuts down any open MySQL Connections
 * @return $g_link = false;
 */
public function CleanUpDB(){
if(
$this->g_link){
   
mysql_close($this->g_link);
    }
    return
$this->g_link = false;
    }
}
//////////////////////////////////////////////////////////
// END OF SQL CLASS //
//////////////////////////////////////////////////////////