/** * @param ResourceInterface $resource * * @param array $options * * @return ResponseInterface */ public function probe(ResourceInterface $resource = null, array $options = []) { $message = sprintf("\nDB DETECTOR:\n====================================\nconnected %s\n====================================\nDRIVER:%s\nDBNAME:%s\n", $this->connectionParams['host'], $this->connectionParams['driver'], $this->connectionParams['dbname']); $successful = false; try { if ($this->connection->ping()) { $successful = true; } } catch (\Exception $e) { $message = sprintf("\nDB DETECTOR:\n====================================\nCODE: %s\nERROR MESSAGE: %s\n", $e->getCode(), IconvHelper::convert($e->getMessage())); } return new DbDetectorResponse($successful, $message, $this->connectionParams); }
/** * Ping the server * * When the server is not available the method returns FALSE. * It is responsibility of the developer to handle this case * and abort the request or reconnect manually: * * @example * * if ($conn->ping() === false) { * $conn->close(); * $conn->connect(); * } * * It is undefined if the underlying driver attempts to reconnect * or disconnect when the connection is not available anymore * as long it returns TRUE when a reconnect succeeded and * FALSE when the connection was dropped. * * @return bool */ public function ping() { $this->connect(); if ($this->_conn instanceof PingableConnection) { return $this->_conn->ping(); } try { $this->query($this->platform->getDummySelectSQL()); return true; } catch (DBALException $e) { return false; } }