本文整理汇总了PHP中mysql_ping函数的典型用法代码示例。如果您正苦于以下问题:PHP mysql_ping函数的具体用法?PHP mysql_ping怎么用?PHP mysql_ping使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mysql_ping函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Page
/**
* ------------------------------
* 构造函数
* ------------------------------
* @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;
}
示例2: Fetch
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;
}
}
示例3: checkRepMySQL
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);
}
}
示例4: do_log_sql
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";
}
示例5: getLink
/**
* return the current link to the database, connect first if needed
*/
public function getLink()
{
if (!mysql_ping($this->link)) {
$this->connect();
}
return $this->link;
}
示例6: __construct
/**
*
* @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);
}
}
示例7: Page
/**
* ------------------------------
* 构造函数
* ------------------------------
* @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;
}
示例8: connected
public function connected()
{
if (is_resource($this->connection)) {
return mysql_ping($this->connection);
}
return false;
}
示例9: sanitize
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;
}
示例10: testConnection
public function testConnection()
{
if (!@mysql_ping($this->QueryManager->_getConnection())) {
return false;
}
return true;
}
示例11: connect
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;
}
示例12: is_connected
function is_connected($connect)
{
if (!mysql_ping($connect)) {
echo 'Lost connection, exiting after query #1';
return false;
}
return true;
}
示例13: check_reconnect
private function check_reconnect()
{
if (!mysql_ping($this->conn)) {
if (!$this->connect()) {
throw new Exception('Error reconnect.');
}
}
}
示例14: ping
function ping()
{
if (!\mysql_ping($this->conn)) {
return false;
} else {
return true;
}
}
示例15: isConnected
private function isConnected()
{
if ($this->cnn === false) {
return false;
} else {
return mysql_ping($this->cnn);
}
}