par
zulgal » 09 nov. 2008, 08:38
voilà jai un soucis de variable (je croit) et je nai pas reussis a trouver le problemes un de vous serait gentil de m'aider

:
voici le fichier dont il est question :
Code : Tout sélectionner
<?php
/*
* 2007 (c) -={MikeP}=-
* Database abstraction layer
*/
require_once('include/settings.php');
class dbLayer {
private $dbConn;
private $result;
private static $wdb;
private static $cdb;
private static $sdb;
// constructor is private so that you can't use it without parameters
private static function connect($login, $password, $host, $db){
// connect to database here and select the database of interest
$dbr = @mysql_connect($host,$login,$password,true);
if(!$dbr) throw new Exception('Unable to connect to database server');
// select the database
if( ! (@mysql_select_db($db,$dbr)) ) throw new Exception('Database is not available.');
return $dbr;
}
private function __construct(&$dbconn){
$this->dbConn = $dbconn;
}
// get character database connection
public static function getCharDB(){
if(!isset(self::$cdb)){
$s = gSettings::get();
self::$cdb = dbLayer::connect($s->db_user, $s->db_password, $s->db_host, $s->db_cname);
}
return new dbLayer(self::$cdb);
}
// get world database connection
public static function getWorldDB(){
if(!isset(self::$wdb)){
$s = gSettings::get();
self::$wdb = dbLayer::connect($s->db_user, $s->db_password, $s->db_host, $s->db_wname);
}
return new dbLayer(self::$wdb);
}
// get site database connection
public static function getSiteDB(){
if(!isset(self::$sdb)){
$s = gSettings::get();
self::$sdb = dbLayer::connect($s->db_user, $s->db_password, $s->db_host, $s->db_sname);
}
return new dbLayer(self::$sdb);
}
// executes the query - returns true on success or throws an exception
public function Execute($query){
// check if we have results from previous query
if( is_resource($this->result) ) @mysql_free_result($this->result);
// now execute the query
$this->result = @mysql_query($query,$this->dbConn);
if( !$this->result ) throw new Exception('Execute query failed: '.mysql_error($this->dbConn));
return true;
}
// fetches one result from the previous Execute call and returns an object.
// returns FALSE on end of rows for SELECT or if result of Execute was not resource
public function Fetch(){
if( is_resource($this->result) ){
return @mysql_fetch_object($this->result);
}else{
return false;
}
}
}
?>
et voici le fichier settings.php si ca peut-etre utile :
Code : Tout sélectionner
<?php
/*
* 2007 (c) -={ MikeP }=-
* Settings class for setting up everything on the site.
* The class is a singleton so that we always have one and only instance of settings.
*/
class gSettings {
// the only instance of the class
private static $instance;
private function __construct(){
//
// here we define all the settings
//
$this->db_user = 'xxxxxxxxxx'; // database user
$this->db_password = 'xxxxxxxxx'; // database password
$this->db_host = 'xxxxx.xxxxxx.com'; // database host:port
$this->db_cname = 'xxxxxxx'; // character database
$this->db_wname = 'xxxxxxx'; // world database
$this->db_sname = ''; //Will be used latertime
$this->statfile = 'xxxxxxx';//Will be used latertime
$this->realm = 'xxxxxxx';
}
private function __clone(){
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
// this is the only way to get properties:
// $props = gSettings::get();
public static function get(){
if(!isset(self::$instance)){
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
}
?>
voilà jai un soucis de variable (je croit) et je nai pas reussis a trouver le problemes un de vous serait gentil de m'aider :) :
voici le fichier dont il est question :
[code]<?php
/*
* 2007 (c) -={MikeP}=-
* Database abstraction layer
*/
require_once('include/settings.php');
class dbLayer {
private $dbConn;
private $result;
private static $wdb;
private static $cdb;
private static $sdb;
// constructor is private so that you can't use it without parameters
private static function connect($login, $password, $host, $db){
// connect to database here and select the database of interest
$dbr = @mysql_connect($host,$login,$password,true);
if(!$dbr) throw new Exception('Unable to connect to database server');
// select the database
if( ! (@mysql_select_db($db,$dbr)) ) throw new Exception('Database is not available.');
return $dbr;
}
private function __construct(&$dbconn){
$this->dbConn = $dbconn;
}
// get character database connection
public static function getCharDB(){
if(!isset(self::$cdb)){
$s = gSettings::get();
self::$cdb = dbLayer::connect($s->db_user, $s->db_password, $s->db_host, $s->db_cname);
}
return new dbLayer(self::$cdb);
}
// get world database connection
public static function getWorldDB(){
if(!isset(self::$wdb)){
$s = gSettings::get();
self::$wdb = dbLayer::connect($s->db_user, $s->db_password, $s->db_host, $s->db_wname);
}
return new dbLayer(self::$wdb);
}
// get site database connection
public static function getSiteDB(){
if(!isset(self::$sdb)){
$s = gSettings::get();
self::$sdb = dbLayer::connect($s->db_user, $s->db_password, $s->db_host, $s->db_sname);
}
return new dbLayer(self::$sdb);
}
// executes the query - returns true on success or throws an exception
public function Execute($query){
// check if we have results from previous query
if( is_resource($this->result) ) @mysql_free_result($this->result);
// now execute the query
$this->result = @mysql_query($query,$this->dbConn);
if( !$this->result ) throw new Exception('Execute query failed: '.mysql_error($this->dbConn));
return true;
}
// fetches one result from the previous Execute call and returns an object.
// returns FALSE on end of rows for SELECT or if result of Execute was not resource
public function Fetch(){
if( is_resource($this->result) ){
return @mysql_fetch_object($this->result);
}else{
return false;
}
}
}
?>
[/code]
et voici le fichier settings.php si ca peut-etre utile :
[code]<?php
/*
* 2007 (c) -={ MikeP }=-
* Settings class for setting up everything on the site.
* The class is a singleton so that we always have one and only instance of settings.
*/
class gSettings {
// the only instance of the class
private static $instance;
private function __construct(){
//
// here we define all the settings
//
$this->db_user = 'xxxxxxxxxx'; // database user
$this->db_password = 'xxxxxxxxx'; // database password
$this->db_host = 'xxxxx.xxxxxx.com'; // database host:port
$this->db_cname = 'xxxxxxx'; // character database
$this->db_wname = 'xxxxxxx'; // world database
$this->db_sname = ''; //Will be used latertime
$this->statfile = 'xxxxxxx';//Will be used latertime
$this->realm = 'xxxxxxx';
}
private function __clone(){
trigger_error('Clone is not allowed.', E_USER_ERROR);
}
// this is the only way to get properties:
// $props = gSettings::get();
public static function get(){
if(!isset(self::$instance)){
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
}
?>[/code]