From 8c93e18d6e527e39c9cf58f53677c1c7d31286df Mon Sep 17 00:00:00 2001 From: Moll <Moll@mhknet.de> Date: Mon, 04 Jul 2016 09:32:09 -0400 Subject: [PATCH] Only if none there is no prefix else it's www --- install/lib/mysql.lib.php | 69 +++++++++++++++++----------------- 1 files changed, 34 insertions(+), 35 deletions(-) diff --git a/install/lib/mysql.lib.php b/install/lib/mysql.lib.php index e151bc4..7cf06ee 100644 --- a/install/lib/mysql.lib.php +++ b/install/lib/mysql.lib.php @@ -60,25 +60,21 @@ //// */ - // constructor - public function __construct($host = NULL , $user = NULL, $pass = NULL, $database = NULL) { - global $conf; - - $this->dbHost = $conf["mysql"]["host"]; - $this->dbName = ''; - $this->dbUser = $conf["mysql"]["admin_user"]; - $this->dbPass = $conf["mysql"]["admin_password"]; - $this->dbCharset = $conf["mysql"]["charset"]; - $this->dbNewLink = false; - $this->dbClientFlags = null; - } - public function __destruct() { if($this->_iConnId) mysqli_close($this->_iConnId); } private function do_connect() { + global $conf; + if($this->_iConnId) return true; + $this->dbHost = $conf["mysql"]["host"]; + $this->dbName = false;//$conf["mysql"]["database"]; + $this->dbUser = $conf["mysql"]["admin_user"]; + $this->dbPass = $conf["mysql"]["admin_password"]; + $this->dbCharset = $conf["mysql"]["charset"]; + $this->dbNewLink = false; + $this->dbClientFlags = null; $this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass); $try = 0; @@ -94,13 +90,26 @@ $this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!'); return false; } + + if($this->dbName) $this->setDBName($this->dbName); + + $this->_setCharset(); + } + + public function setDBData($host, $user, $password) { + $this->dbHost = $host; + $this->dbUser = $user; + $this->dbPass = $password; + } + + public function setDBName($name) { + $this->dbName = $name; + $this->_iConnId = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPass); if(!((bool)mysqli_query( $this->_iConnId, 'USE `' . $this->dbName . '`'))) { $this->close(); $this->_sqlerror('Datenbank nicht gefunden / Database not found'); return false; } - - $this->_setCharset(); } public function close() { @@ -136,8 +145,10 @@ if($iPos2 !== false && ($iPos === false || $iPos2 <= $iPos)) { $sTxt = $this->escape($sValue); - if(strpos($sTxt, '.') !== false) $sTxt = preg_replace('/^(.+)\.(.+)$/', '`$1`.`$2`', $sTxt); - else $sTxt = '`' . $sTxt . '`'; + if(strpos($sTxt, '.') !== false) { + $sTxt = preg_replace('/^(.+)\.(.+)$/', '`$1`.`$2`', $sTxt); + $sTxt = str_replace('.`*`', '.*', $sTxt); + } else $sTxt = '`' . $sTxt . '`'; $sQuery = substr_replace($sQuery, $sTxt, $iPos2, 2); $iPos2 += strlen($sTxt); @@ -178,11 +189,8 @@ } private function _query($sQuery = '') { - global $app; - $this->do_connect(); - //if($this->isConnected == false) return false; if ($sQuery == '') { $this->_sqlerror('Keine Anfrage angegeben / No query given'); return false; @@ -197,10 +205,8 @@ if($this->errorNumber == '111') { // server is not available if($try > 9) { - if(isset($app) && isset($app->forceErrorExit)) { - $app->forceErrorExit('Database connection failure!'); - } - // if we reach this, the app object is missing or has no exit method, so we continue as normal + $this->_sqlerror('DB::query -> error connecting'); + exit; } sleep(30); // additional seconds, please! } @@ -432,18 +438,13 @@ * @return string escaped string */ public function escape($sString) { - global $app; if(!is_string($sString) && !is_numeric($sString)) { - $app->log('NON-String given in escape function! (' . gettype($sString) . ')', LOGLEVEL_INFO); - //$sAddMsg = getDebugBacktrace(); - $app->log($sAddMsg, LOGLEVEL_DEBUG); $sString = ''; } $cur_encoding = mb_detect_encoding($sString); if($cur_encoding != "UTF-8") { if($cur_encoding != 'ASCII') { - $app->log('String ' . substr($sString, 0, 25) . '... is ' . $cur_encoding . '.', LOGLEVEL_INFO); if($cur_encoding) $sString = mb_convert_encoding($sString, 'UTF-8', $cur_encoding); else $sString = mb_convert_encoding($sString, 'UTF-8'); } @@ -461,7 +462,7 @@ * @access private */ private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '') { - global $app, $conf; + global $conf; $mysql_error = (is_object($this->_iConnId) ? mysqli_error($this->_iConnId) : mysqli_connect_error()); $mysql_errno = (is_object($this->_iConnId) ? mysqli_errno($this->_iConnId) : mysqli_connect_errno()); @@ -470,9 +471,7 @@ if($this->show_error_messages && $conf['demo_mode'] === false) { echo $sErrormsg . $sAddMsg; - } else if(is_object($app) && method_exists($app, 'log')) { - $app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN); - } + } } public function affectedRows() { @@ -777,7 +776,7 @@ * * @access private */ - public function db_result($iResId, $iConnection) { + public function __construct($iResId, $iConnection) { $this->_iResId = $iResId; $this->_iConnection = $iConnection; } @@ -903,7 +902,7 @@ * * @access private */ - public function fakedb_result($aData) { + public function __construct($aData) { $this->aResultData = $aData; $this->aLimitedData = $aData; reset($this->aLimitedData); -- Gitblit v1.9.1