當前位置: 首頁>>代碼示例>>PHP>>正文


PHP mysqli::ping方法代碼示例

本文整理匯總了PHP中mysqli::ping方法的典型用法代碼示例。如果您正苦於以下問題:PHP mysqli::ping方法的具體用法?PHP mysqli::ping怎麽用?PHP mysqli::ping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mysqli的用法示例。


在下文中一共展示了mysqli::ping方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isConnected

 /**
  * is the MySQL server connected?
  * @return boolean
  */
 function isConnected()
 {
     if (php_sapi_name() == 'fpm-fcgi') {
         return $this->mysqli != null;
     }
     //Web requests are short
     return $this->mysqli && @$this->mysqli->ping();
 }
開發者ID:splitice,項目名稱:radical-db,代碼行數:12,代碼來源:MysqlStaticConnector.php

示例2: _getMysqli

 /**
  * connect to the db and save the connection
  * @throws \Exception
  * @return bool|\mysqli
  */
 private function _getMysqli()
 {
     if (!$this->_mysqli instanceof \mysqli) {
         $this->_mysqli = @new \mysqli(static::DB_HOSTNAME, static::DB_USERNAME, static::DB_PASSWORD, static::DB_DATABASE, static::DB_PORT);
         if ($this->_mysqli->connect_error) {
             throw new \Exception("Error connecting to database: {$this->_mysqli->connect_error}");
         }
     } else {
         if (!$this->_mysqli->ping()) {
             $this->_mysqli = null;
             $this->_getMysqli();
         }
     }
     return $this->_mysqli;
 }
開發者ID:epoplive,項目名稱:shorty,代碼行數:20,代碼來源:Shorty.php

示例3: query

 /**
  * Prepares a sql query optionally as a prepared statement if the prepArgs
  * array is specified
  * @name query
  * @param str $sql SQL to execute
  * @param str $prepArgs Arguments for prepared statement queries
  * @since 0.1.0
  * @return object query results
  * <code>
  * <?php
  * $query = $db->query("select * from foo")
  *
  * //prepared (safe from injection)
  * $query = $db->query("select * from foo where foo_id = ?", ['i', 1]);
  *
  * ?>
  * </code>
  */
 public function query($sql, $prepArgs = false)
 {
     if (!$this->conn->ping()) {
         $this->conn->close();
         $this->connect();
     }
     try {
         if (is_array($prepArgs)) {
             $stmt = $this->conn->prepare($sql);
             if (false === $stmt) {
                 $this->error("Couldn't prepare statement: " . $this->conn->error);
             } else {
                 $method = new \ReflectionMethod('mysqli_stmt', 'bind_param');
                 $method->invokeArgs($stmt, $this->_mkrefs($prepArgs));
                 /* much love to jan kriedner */
                 $stmt->execute();
                 if ($stmt->insert_id > 0) {
                     $result = $stmt->insert_id;
                 } else {
                     $result = $stmt->get_result();
                 }
             }
         } else {
             $result = $this->conn->query($sql);
         }
     } catch (Exception $e) {
         $this->error($e->getMessage() . " SQL: {$sql}");
     }
     return $result;
 }
開發者ID:willgriffin,項目名稱:mariainterface,代碼行數:48,代碼來源:MariaInterface.php

示例4: connected

 /**
  * Determines if the connection to the server is active.
  *
  * @return  boolean  True if connected to the database engine.
  *
  * @since   1.0
  */
 public function connected()
 {
     if (is_object($this->connection)) {
         return $this->connection->ping();
     }
     return false;
 }
開發者ID:jbanety,項目名稱:database,代碼行數:14,代碼來源:MysqliDriver.php

示例5: measurePing

 public function measurePing(&$micro)
 {
     $micro = -microtime(true);
     $result = $this->mysqli->ping();
     $micro += microtime(true);
     return $result;
 }
開發者ID:LegionPE,項目名稱:LegionPE-Eta,代碼行數:7,代碼來源:MysqlConnection.php

示例6: ping

 public function ping()
 {
     if (!@$this->handler->ping()) {
         return $this->reconnect();
     }
     return true;
 }
開發者ID:Lazary,項目名稱:webasyst,代碼行數:7,代碼來源:waDbMysqliAdapter.class.php

示例7: ping

 /**
  * Ping a server connection or reconnect if there is no connection
  * @return bool
  */
 public function ping()
 {
     if (!$this->dbh) {
         return false;
     }
     return @$this->dbh->ping();
 }
開發者ID:mpeshev,項目名稱:wp-db-driver,代碼行數:11,代碼來源:mysqli.php

示例8: reconnect

 public function reconnect()
 {
     if (!$this->mysqli->ping()) {
         $this->mysqli->close();
         return $this->connect();
     }
     return true;
 }
開發者ID:Val-Git,項目名稱:icms2,代碼行數:8,代碼來源:database.php

示例9: testMysqliConnection

 public function testMysqliConnection()
 {
     $mysqliConn = new mysqli("localhost", "root", "eqBZKHCd775HA2fS", "JobGossip");
     $connection = $mysqliConn->ping();
     $this->assertTrue($connection);
     $mysqliConn->close();
     //cleanup test
 }
開發者ID:bryanbailey,項目名稱:TEAM6_Jossip,代碼行數:8,代碼來源:createJobPostTest.php

示例10: setDatabase

 public static function setDatabase(mysqli $db)
 {
     self::$db = null;
     if ($db && $db->ping()) {
         self::$db = $db;
         return true;
     }
     return false;
 }
開發者ID:pontifechs,項目名稱:reports,代碼行數:9,代碼來源:DBService.php

示例11: reconnect

 /**
  * Reconnect to the db server
  */
 public function reconnect()
 {
     if (isset($this->native) && @$this->native->ping()) {
         return;
     }
     $native = new mysqli($this->settings['host'], $this->settings['user'], $this->settings['password'], $this->settings['dbname'], $this->settings['port'], $this->settings['unix_socket']);
     if (!$native) {
         throw new DB_Exception("Connecting to mysql database failed: " . \mysqli::connect_error());
     }
     $this->native = $native;
 }
開發者ID:jasny,項目名稱:Q,代碼行數:14,代碼來源:MySQL.php

示例12: __destruct

 /**
  * Destructor: cierra la conexión a MySQL si está abierta
  * @throws DBException si no se puede cerrar la conexion
  */
 public function __destruct()
 {
     try {
         $pingResult = parent::ping();
     } catch (\Exception $e) {
         $pingResult = false;
     }
     if ($pingResult) {
         if (!parent::close()) {
             throw new DBException(mysqli_connect_error(), mysqli_connect_errno());
         }
     }
 }
開發者ID:neslonso,項目名稱:Sintax,代碼行數:17,代碼來源:MysqliDB.php

示例13: isConnected

 /**
  * Is connected
  *
  * @return bool
  */
 public function isConnected()
 {
     if ($this->resource instanceof \mysqli) {
         // 檢測連接是否有效
         if (!$this->resource->ping()) {
             $this->disconnect();
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
開發者ID:xudianyang,項目名稱:yafrk-lib,代碼行數:18,代碼來源:Connection.php

示例14: lazyConnect

 /**
  * If there is no DB connection established yet, it connects and populates self::$connection attribute.
  *
  * Also "wakes up" connection if it has gone away.
  */
 protected function lazyConnect()
 {
     if (isset($this->connection)) {
         // Connection might have gone away.
         $this->connection->ping();
         return;
     }
     list($host, $user, $password, $database) = $this->config->getMulti(array('db_host', 'db_user', 'db_password', 'db_name'));
     $this->connection = new mysqli($host, $user, $password);
     if (mysqli_connect_errno()) {
         throw new PHPTracker_Persistence_Error('Unable to connect to mysql database: ' . mysqli_connect_error());
     }
     if (false === $this->connection->select_db($database)) {
         throw new PHPTracker_Persistence_Error("Unable to select database: {$database}.\n" . $this->connection->error);
     }
 }
開發者ID:r15ch13,項目名稱:PHPTracker,代碼行數:21,代碼來源:Mysql.php

示例15: probarConeccion

 public function probarConeccion()
 {
     $mysqli = new mysqli("104.236.75.102", "monty", "rioslopez", "itcVolBank");
     /* check connection */
     if ($mysqli->connect_errno) {
         printf("Connect failed: %s\n", $mysqli->connect_error);
         exit;
     }
     /* check if server is alive */
     if ($mysqli->ping()) {
         printf("Our connection is ok!\n");
     } else {
         printf("Error: %s\n", $mysqli->error);
     }
     /* close connection */
     $mysqli->close();
 }
開發者ID:fcrios145,項目名稱:Itcvolbank,代碼行數:17,代碼來源:mysqlConnection.php


注:本文中的mysqli::ping方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。