当前位置: 首页>>代码示例>>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;未经允许,请勿转载。