Ok so this is just an insider to a new project im working on
now this project is a professional website that is built on PHP 5.1+ and will not be released under any licence and im not going to be telling you what the site is etc because i like to keep my professional work seperate to my fun work.. aka the scene so here take a look at it
mysql.class.php
Heres my Registry where all my Objects are help and passed threw out other classes for ease of use
and heres the example of how the index file looks but not showing all the source :P
now if your thinking why dont i show you this in my tutorials is because no one on this site is ready for this so to speak
but enjoy looking at my source and comment on what you think of my OOP :P
now this project is a professional website that is built on PHP 5.1+ and will not be released under any licence and im not going to be telling you what the site is etc because i like to keep my professional work seperate to my fun work.. aka the scene so here take a look at it
mysql.class.php
PHP:
<?php
class MySql{
var $settings = array();
var $handlers = array();
var $errors = array();
var $query_Data = array();
function __construct($host,$user,$pass,$db){
$this->settings['credentials']['host'] = $host;
$this->settings['credentials']['user'] = $user;
$this->settings['credentials']['pass'] = $pass;
$this->settings['credentials']['data'] = $db;
//Start the connection
$this->__Connect();
$this->__Assoc_Database();
//Some Charactor Setting
mysql_query("SET NAMES 'utf8'",$this->handlers['connect']);
mysql_query("SET CHARASET SET 'utf8'",$this->handlers['connect']);
}
public function query($query){
$resource = mysql_query($query);
if($resource){
if(is_resource($resource)){
//Set some vars
$i = 0;
$data = array();
//Loop the results
while($row = mysql_fetch_assoc($resource)){
$this->query_Data[$i] = $row;
$i++; //Post ++
}
mysql_free_result($resource);
$query = new stdClass();
$query->row = (isset($this->query_Data[0]) ? $this->query_Data : array());
$query->rows = $this->query_Data;
$query->numrows = $i;
unset($this->query_Data);
return $query;
}
}else{
$this->__Error(__FILE__,__CLASS__,__METHOD__,__LINE__,mysql_error());
}
}
private function __Connect(){
$this->handlers['connect'] = mysql_connect(
$this->settings['credentials']['host'],
$this->settings['credentials']['user'],
$this->settings['credentials']['pass']) or
$this->__Error(__FILE__,__CLASS__,__METHOD__,__LINE__,mysql_error());
}
private function __Assoc_Database(){
$this->handlers['database'] = mysql_select_db(
$this->settings['credentials']['data']) or
$this->__Error(__FILE__,__CLASS__,__METHOD__,__LINE__,mysql_error());
}
private function __Error($file,$class,$funtion,$line,$error){
die(
sprintf("<pre class='error_php_internal'>There was an error\rFILE: %s\rCLASS: %s\rMETHOD: %s\rLINE: %d\rERROR: %s</pre>",
$file,
$class,
$function,
$line,
$error)
);
}
public function hello(){
echo 'hello';
}
function __destruct(){
mysql_close($this->handlers['connect']);
unset(
$this->settings,
$this->handlers,
$this->errors,
$this->query_Data
);
}
}
?>
Heres my Registry where all my Objects are help and passed threw out other classes for ease of use
PHP:
<?php
//used for holding objects on one array() ....
final class Registry{
static private $data = array();
static public function get($key){
return (isset(self::$data[$key]) ? self::$data[$key] : NULL);
}
static public function set($key,$value){
self::$data[$key] = $value;
}
static function has($key){
return isset(self::$data[$key]);
}
}
?>
and heres the example of how the index file looks but not showing all the source :P
PHP:
<?php
//Include Main Config
include 'config.php';
//Include Startup
include $settings['dir']['includes'] . 'startup.php';
//Sessions
Registry::set('sessions',new Sessions);
//Config
$Config = new Config;
Registry::set('config',$Config);
//Mysql
$MySql = new MySql($settings['mysql']['host'],$settings['mysql']['user'],$settings['mysql']['pass'],$settings['mysql']['data']);
Registry::set('mysql',$MySql);
//Settings (keep uppercase because it will overide the config file);
$Settings = $MySql->query('SELECT * FROM settings');
foreach($Settings->rows as $row){$Config->set($row['key'], $row['value']);}
$Templater = new Templater;
Registry::set('Templater',$Templater);
?>
now if your thinking why dont i show you this in my tutorials is because no one on this site is ready for this so to speak
but enjoy looking at my source and comment on what you think of my OOP :P