Example #1
0
 /**
  * ------------------------------
  * 构造函数
  * ------------------------------
  * @param  string $tbname   要操作的表名
  * @param  string $where    定位条件
  * @param  string $field    要查询的字段
  * @param  string $pageSize 每页显示数量
  * @param  string $orderBy  排序方式
  */
 function Page($tbname, $where = '1=1', $field = '*', $pageSize = 10, $orderBy = '')
 {
     !extension_loaded('mysql') && exit('mysql do not exist!');
     !mysql_ping() && exit('mysql can not connect!');
     if ($where == '') {
         $where = '1=1';
     }
     if ($field == '') {
         $field = '*';
     }
     $this->pageSize = $pageSize;
     //获取总记录条数
     $sql = "SELECT count(*) as row_num FROM `{$tbname}` WHERE {$where}";
     $row_num = mysql_fetch_array(mysql_query($sql));
     $this->totalNum = $row_num['row_num'];
     $this->totalPage = ceil($this->totalNum / $this->pageSize);
     //获得当前page
     $page = isset($_GET['page']) && $_GET['page'] != '' ? ceil($_GET['page']) : 1;
     $this->page = $page < $this->totalPage ? $page : $this->totalPage;
     $this->page = $this->page < 1 ? 1 : $this->page;
     //计算查询的起始值
     $start = ($this->page - 1) * $this->pageSize;
     //查询结果
     //$sql = "SELECT $field FROM $tbname WHERE $where AND id > $start ORDER BY id ASC".($orderBy ? ",$orderBy" : '')." LIMIT $this->pageSize";
     $sql = "SELECT {$field} FROM `{$tbname}` WHERE {$where}" . ($orderBy ? ' ORDER BY ' . $orderBy : '') . " LIMIT {$start},{$this->pageSize}";
     $result = mysql_query($sql);
     $data = array();
     while ($row = mysql_fetch_assoc($result)) {
         $data[] = $row;
     }
     $this->data = $data;
 }
Example #2
0
	function Fetch($url, $data = null, $usecache = TRUE) {
		if ($usecache && $content = $this->GetCached($url, $data)) {
			return $content;
		} else {
			$curl = curl_init();
			curl_setopt($curl, CURLOPT_URL, $url);
			curl_setopt($curl, CURLOPT_HEADER, 0);
			curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
			curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
			if ($data) {
				curl_setopt($curl, CURLOPT_POST, 1);
				curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
			}

			if(!$content = curl_exec($curl))
				$this->site->Error('CURL Error: ' . curl_error($curl));

			if (!mysql_ping()) { // If the MySQL connection dropped (WHO connections can take AGES) reestablish
				$this->db->close();
				$this->db->initialize();
			}

			$this->SaveCached($url, $data, $content);
			return $content;
		}
	}
Example #3
0
function checkRepMySQL()
{
    if (!Globals::$rep_mysql or !mysql_ping(Globals::$rep_mysql)) {
        Globals::$rep_mysql = mysql_pconnect(Config::$rep_mysqlhost . ':' . Config::$rep_mysqlport, Config::$rep_mysqluser, Config::$rep_mysqlpass);
        mysql_select_db(Config::$rep_mysqldb, Globals::$rep_mysql);
    }
}
Example #4
0
function do_log_sql($stdlog, $text_log, &$LINK)
{
    if (!mysql_ping($GLOBALS["LINK"])) {
        $do_mysql_reconect = 1;
        fputs($stdlog, get_date() . " MySQL Connect failed" . "\n");
    } else {
        $do_mysql_reconect = 0;
        fputs($stdlog, get_date() . " " . $text_log . "\n");
    }
    while ($do_mysql_reconect == 1) {
        $config_file = '../../app/etc/config.xml';
        if (file_exists($config_file)) {
            $xml = simplexml_load_file($config_file);
            $CONF_MYSQL_HOST = (string) $xml->parameters->mysql->host;
            $CONF_MYSQL_USERNAME = (string) $xml->parameters->mysql->username;
            $CONF_MYSQL_PASSWORD = (string) $xml->parameters->mysql->password;
            $CONF_MYSQL_DBNAME = (string) $xml->parameters->mysql->dbname;
        }
        $GLOBALS["LINK"] = mysql_pconnect($CONF_MYSQL_HOST, $CONF_MYSQL_USERNAME, $CONF_MYSQL_PASSWORD);
        mysql_select_db($CONF_MYSQL_DBNAME, $GLOBALS["LINK"]);
        if (mysql_ping($GLOBALS["LINK"])) {
            $do_mysql_reconect = 0;
            fputs($stdlog, get_date() . " MySQL Connect restored" . "\n");
        }
    }
    return "1";
}
 /**
  * return the current link to the database, connect first if needed
  */
 public function getLink()
 {
     if (!mysql_ping($this->link)) {
         $this->connect();
     }
     return $this->link;
 }
Example #6
0
    /**
	 * 
	 * @description 析构函数,该分页类创建对象时,自动调用
	 * 对sql语句进行判断,获取文章每页显示数
	 * @param string $sql
    */
    public function __construct($sql,$CycNum = 5){
        if(!@mysql_ping()){
            echo "Please check your database link";
            exit;
        }
        if(is_numeric($CycNum)){
            $this->CycNum = $CycNum;
        }else{
            $this->CycNum = $this->CycNum;
        }
        if(trim($sql) != ""){
            if(preg_match("/limit/",$sql)){
                list($sql,$limit)	=	explode("limit",$sql);
            }else if(preg_match("/LIMIT/",$sql)){
                list($sql,$limit)	=	explode("LIMIT",$sql);
            }
            //$this->QueryString = $sql;
            if(isset($limit)){
                list($cnt1,$cnt2)	=	explode(",",$limit);
                if(!empty($cnt2)){
                    $this->PageSize = $cnt2;
                }elseif(!empty($cnt1)){
                    $this->PageSize = $cnt1;
                }else{
                    $this->PageSize = $this->PageSize;
                }
            }
            $this->QueryString = $sql;
            unset($cnt1);
            unset($cnt2);
        }
    }
Example #7
0
 /**
  * ------------------------------
  * 构造函数
  * ------------------------------
  * @param  string $tbname   要操作的表名
  * @param  string $where    定位条件
  * @param  string $field    要查询的字段
  * @param  string $pageSize 每页显示数量
  * @param  string $orderBy  排序方式
  */
 function Page($tbname, $where = '1=1', $field = '*', $page_size = 20, $order_by = '', $group_by = '')
 {
     !mysql_ping() && exit('mysql can not connect!');
     //获取总记录条数
     if ($group_by) {
         $sql = "SELECT count(DISTINCT {$group_by}) as row_num FROM {$tbname} WHERE {$where}";
     } else {
         $sql = "SELECT count(*) as row_num FROM {$tbname} WHERE {$where}";
     }
     $row_num = mysql_fetch_array(mysql_query($sql));
     $this->total_num = $row_num['row_num'];
     $this->total_page = ceil($this->total_num / $page_size);
     //当前page
     $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
     $this->page = $page < $this->total_page && $this->page != 0 ? $page : $this->total_page;
     //计算查询的起始值
     $start = ($this->page - 1) * $page_size;
     //查询结果
     if ($group_by) {
         $sql = "SELECT {$field} FROM {$tbname} WHERE {$where} GROUP BY {$group_by}" . ($order_by ? ' ORDER BY ' . $order_by : '') . " LIMIT {$start},{$this->page_size}";
     } else {
         $sql = "SELECT {$field} FROM {$tbname} WHERE {$where}" . ($order_by ? ' ORDER BY ' . $order_by : '') . " LIMIT {$start},{$this->page_size}";
     }
     $result = mysql_query($sql);
     $data = array();
     while ($row = mysql_fetch_assoc($result)) {
         $data[] = $row;
     }
     $this->data = $data;
 }
Example #8
0
 public function connected()
 {
     if (is_resource($this->connection)) {
         return mysql_ping($this->connection);
     }
     return false;
 }
Example #9
0
function sanitize($vals, $html = false)
{
    $val = '';
    if (!($vals = (array) $vals)) {
        return false;
    }
    foreach ($vals as &$val) {
        if ($html) {
            $val = htmlentities($val, ENT_NOQUOTES, 'UTF-8', false);
        }
        if (is_array($val)) {
            foreach ($val as &$v) {
                $v = sanitize($v);
            }
        } elseif (@mysql_ping()) {
            if (get_magic_quotes_gpc()) {
                $val = stripslashes($val);
            }
            $val = mysql_real_escape_string(trim($val));
        } elseif (!get_magic_quotes_gpc()) {
            $val = addslashes(trim($val));
        }
    }
    return count($vals) > 1 ? $vals : $val;
}
Example #10
0
 public function testConnection()
 {
     if (!@mysql_ping($this->QueryManager->_getConnection())) {
         return false;
     }
     return true;
 }
Example #11
0
 public static function connect()
 {
     if (!self::$connection || !mysql_ping(self::$connection)) {
         self::$connection = mysql_connect(self::$Config['host'], self::$Config['username'], self::$Config['password']);
     }
     mysql_select_db(self::$Config['database'], self::$connection);
     return self::$connection;
 }
Example #12
0
function is_connected($connect)
{
    if (!mysql_ping($connect)) {
        echo 'Lost connection, exiting after query #1';
        return false;
    }
    return true;
}
Example #13
0
 private function check_reconnect()
 {
     if (!mysql_ping($this->conn)) {
         if (!$this->connect()) {
             throw new Exception('Error reconnect.');
         }
     }
 }
Example #14
0
 function ping()
 {
     if (!\mysql_ping($this->conn)) {
         return false;
     } else {
         return true;
     }
 }
 private function isConnected()
 {
     if ($this->cnn === false) {
         return false;
     } else {
         return mysql_ping($this->cnn);
     }
 }
Example #16
0
 public function isConnected()
 {
     if (!empty($this->link)) {
         return @mysql_ping($this->link);
     } else {
         return false;
     }
 }
 function trans_rollback()
 {
     if ($this->transtarted && mysql_ping() && $this->transenabled) {
         $this->transtarted = false;
         $this->outputmsg("Rolling Back Transaction");
         mysql_query("ROLLBACK");
     }
 }
Example #18
0
/**
 * Lav et database kald. Erstat alle spørgsmålstegn med værdierne i parameter-
 * arrayet med quotetegn omkring. Brug PHP værdien null til at sætte et felt til
 * SQL værdien NULL. Brug kun parameter-arrayet til data værdier, og ikke
 * tabelnavn eller feltnavne. Disse bør i stedet blive tjekket mod whitelist og
 * indsat direkte i forespørgselsstrengen q.
 *
 * Kan kaste en DatabaseException.
 * Kan kaste en TriggerDatabaseException.
 *
 * @param string $q MySQL forespørgselsstreng
 * @param $parametre Array af værdier der skal erstatte
 *	spørgsmålstegnene
 * @return Et array med maps
 */
function backend_dbquery($q, $parametre = null)
{
    static $mysqlhandle;
    // forbind hvis ikke forbundet allerede
    if ($mysqlhandle == null || !mysql_ping($mysqlhandle)) {
        $mysqlhandle = @mysql_connect(KOLSYSTEM_DB_HOST, KOLSYSTEM_DB_USERNAME, KOLSYSTEM_DB_PASSWORD);
        if (!$mysqlhandle) {
            throw new backend_database_exception('could not connect to db');
        }
        if (!mysql_select_db(KOLSYSTEM_DB_NAME)) {
            throw new backend_database_exception(mysql_error($mysqlhandle));
        }
        mysql_set_charset('utf8', $mysqlhandle);
    }
    // indsæt værdier
    if ($parametre != null) {
        $qx = explode('?', $q);
        if (count($qx) - 1 != count($parametre)) {
            throw new backend_parameter_fejl_database_exception();
        }
        $q = '';
        for ($i = 0; $i < count($parametre); $i++) {
            if ($parametre[$i] === null) {
                $s = 'NULL';
            } else {
                $s = "'" . mysql_real_escape_string($parametre[$i]) . "'";
            }
            $q .= $qx[$i] . $s;
        }
        $q .= $qx[count($qx) - 1];
    }
    // kør forespørgsel
    $result = mysql_query($q, $mysqlhandle);
    if ($result === false) {
        if (strpos(mysql_error($mysqlhandle), 'TRIGGER_DUMMY_') !== false) {
            // exceptions kastet fra en trigger er lavet ved at lave calls
            // til ikke-eksisterende dummy stored procedures, der har
            // prefixene TRIGGER_DUMMY_
            preg_match('/TRIGGER_DUMMY_(.*?) /', mysql_error($mysqlhandle), $r);
            throw new backend_trigger_database_exception($r[1]);
        } else {
            throw new backend_database_exception(mysql_error($mysqlhandle));
        }
        // her skal måske kastes flere forskellige exceptions efter hvad
        // fejltypen er
    }
    if ($result === true) {
        return;
    }
    // hent alle returværdier til et simpelt PHP array
    $ret = array();
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            $ret[] = $row;
        }
    }
    return $ret;
}
 public function get_dbh_no_db_selected()
 {
     $password_file = $this->get_password_file();
     $dbh = @mysql_pconnect($password_file->get_host(), 'root', $_SESSION['mysql-root-password']);
     if (!isset($dbh) or !@mysql_ping($dbh)) {
         throw new Exception('Unable to connect as ' . 'root' . '@' . $password_file->get_host() . '!');
     }
     return $dbh;
 }
Example #20
0
function db_ping($name = "default")
{
    $i = _db($name);
    if (mysql_ping($i) == False) {
        mysql_close($i);
        unset($GLOBALS["_db_instance_{$name}"]);
    }
    return _db($name);
}
Example #21
0
 /** @return bool */
 public function ping()
 {
     $ping = mysql_ping($this->conn);
     if ($ping) {
         return true;
     }
     $this->open();
     return true;
 }
Example #22
0
 function reconnect()
 {
     if (mysql_ping($this->dou_link) === FALSE) {
         mysql_close($this->dou_link);
         $this->dou_link = FALSE;
     }
     if (!$this->dou_link) {
         $this->connect();
     }
 }
Example #23
0
 private function db_write()
 {
     if (isset($this->db_write)) {
         mysql_ping($this->db_write);
         return $this->db_write;
     } else {
         $this->db_write = $this->connect(true);
         return $this->db_write;
     }
 }
Example #24
0
 /**
  * <b>Methodo</b>
  * Cria o banco de dados
  */
 public static function createDataBase($host, $port, $database, $user, $pass)
 {
     $link = mysql_connect("{$host}:{$port}", $user, $pass);
     if (!$link || !mysql_ping($link)) {
         // teste do banco de dados
         throw new Exception("Falha na conexão com o banco de dados. <br/> Certifique-se de que o usuário e senha estão corretos. <br/> Verifique as permissões do usuário do banco.");
     }
     self::mysql_install_db($database, 'common/bd/database.sql');
     self::configDataBase($host, $port, $database, $user, $pass);
 }
 private function checkConnection()
 {
     if (!$this->_handle || !mysql_ping($this->_handle)) {
         $this->_handle = mysql_connect($this->_host, $this->_user, $this->_password);
         mysql_query('SET NAMES \'utf8\' COLLATE \'utf8_general_ci\'');
         if (!mysql_select_db($this->_dbase, $this->_handle)) {
             $this->errmess(mysql_error($this->_handle) . "<br>host: {$host}<br>");
         }
     }
 }
Example #26
0
File: db.php Project: thu0ng91/jmc
 /**
  * 重新连接数据库
  * 
  * @param      void       
  * @access     public
  * @return     bool
  */
 function reconnect()
 {
     if (!mysql_ping($this->conn)) {
         $this->close();
         return $this->connect($this->links['dbhost'], $this->links['dbuser'], $this->links['dbpass'], $this->links['dbname'], $this->links['selectdb']);
     } else {
         $this->connectcharset();
         return true;
     }
 }
function reconnect()
{
    global $dbConn;
    if (mysql_ping()) {
        return;
    }
    $db_config = C("DB_CONFIG");
    $dbConn = new mysql();
    $dbConn->connect($db_config["master1"][0], $db_config["master1"][1], $db_config["master1"][2]);
    $dbConn->select_db($db_config["master1"][4]);
}
Example #28
0
 public static function ping()
 {
     if (!mysql_ping(self::$link)) {
         mysql_close(self::$link);
         // close the connection
         self::$link = @mysql_connect(core::$config->database->server, core::$config->database->user, core::$config->database->pass);
         // can we connect to sql?
         @mysql_select_db(core::$config->database->name, self::$link);
         // can we select the database?
     }
 }
Example #29
0
 private function check_connect()
 {
     if (!$this->conn || !is_resource($this->conn)) {
         $this->connect_db();
     } else {
         if (!mysql_ping($this->conn)) {
             mysql_close($this->conn);
             $this->connect_db();
         }
     }
 }
 /**
  * @param string $db
  *             the joomla database connection
  */
 function fb_DB_Iterator($db)
 {
     $this->db = $db;
     # decide connector... pretty ugly in joomla since there's nothing like related config
     if (function_exists('mysql_ping')) {
         if (!@mysql_ping($db->_resource)) {
             $this->ctype = 'mysqli';
         }
     }
     $this->result = $db->query();
 }