X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=inc%2Fdatabase.inc;h=53f698d5588c649bc8a6b65644ba3ec369cff10d;hb=b42b2bf946332ad8544d53f610be9cb05e80bf56;hp=12b87fa0b2630bd8fe8ed516cd74a9cf7e3cdafa;hpb=e586807dafc64c3fe152ab518599e6cf3f0f84e1;p=mirrors%2FKyberia-bloodline.git
diff --git a/inc/database.inc b/inc/database.inc
old mode 100755
new mode 100644
index 12b87fa..53f698d
--- a/inc/database.inc
+++ b/inc/database.inc
@@ -1,19 +1,16 @@
Database=$database;
$this->Password=$password;
$this->User=$user;
$this->Url=$url;
- $this->connect($this->Url,$this->User,$this->Password,$this->Database);
+*/
+
+function CLASS_DATABASE() {
+ $this->connect(DB_HOST,DB_USER,DB_PASS,DB_DATABASE);
}
-function connect($url, $user, $password, $database, $halt_on_error = true) {
+function connect($url,$user,$password,$database, $halt_on_error = true) {
global $error;
$this->_halt_on_error = $halt_on_error;
if ($this->_linkId == false) {
-
$this->_linkId=mysql_connect($url, $user, $password);
if ($this->_linkId == false) {
$error='chcipla databaza';
$this->exception($error);
return false;
//die();
- }
+ }// else {
+ // mysql_query('set character set utf8');
+ //}
$this->_url=$url;
$this->_user=$user;
$this->_password=$password;
@@ -61,11 +63,26 @@ function closeMysql() {
function query($sql) {
+// if (preg_match("/^select/i",$sql) && (rand(0,1000)>MASTER2SLAVE) && $this->Master) {
+// every select query goes to onyx + opraveny regexp, aby matchoval vnorene selecty (br)
+ if (preg_match('/^\(?select/i',$sql) && $this->Master) {
+ $this->_linkId = false;
+ $this->connect(SLAVE_HOST,SLAVE_USER,SLAVE_PASS,SLAVE_DATABASE);
+ $this->Master = false;
+
+ }
+ elseif (!preg_match("/^select/i",$sql) && !$this->Master) {
+ $this->_linkId = false;
+ $this->connect(DB_HOST,DB_USER,DB_PASS,DB_DATABASE);
+ $this->Master = true;
+ }
$this->_queryId = mysql_query($sql,$this->_linkId);
- if ($_SESSION['user_id']==548) {
+ if ($_SESSION['debugging']) {
+ if ($this->Master) echo "Master::";
+ else echo "Slave::";
echo $sql;
global $timer_start;
echo "
".SubStr((Time()+SubStr(MicroTime(),0,8)-$timer_start),0,7);
@@ -99,6 +116,11 @@ function executeupdate($sql) {
}
function update($sql) {
+ if (!$this->Master) {
+ $this->_linkId = false;
+ $this->connect(DB_HOST,DB_USER,DB_PASS,DB_DATABASE);
+ $this->Master = true;
+ }
$this->_queryId = @mysql_db_query($this->_database,$sql,$this->_linkId);
if ($this->_queryId == false) {
@@ -113,9 +135,11 @@ function getLastInsertId() {
}
function exception($errorMessage) {
+
echo "";
+
if ($this->_halt_on_error) {
die("
".$errorMessage.""); } else { @@ -124,4 +148,4 @@ function exception($errorMessage) { } } } -?> \ No newline at end of file +?>