I have the following class:
<?php
require 'config.php';
ini_set('display_errors', 0);
abstract class Conexion {
protected $conexion;
function __construct() {
}
function __destruct() {
// $this->close();
}
protected function abrirConexion() {
try {
$this->conexion = new mysqli(BD_HOST, BD_USUARIO, BD_CLAVE, BD_BASEDEDATOS, BD_PUERTO, BD_SOCKET);
if ($this->conexion->errno == 0) {
$this->conexion->query("SET NAMES utf8");
return true;
} else {
$this->cerrarConexion();
return false;
}
} catch (Exception $e) {
return false;
}
}
protected function cerrarConexion() {
$this->conexion->close();
}
}
and I want to catch the errors and exceptions that may occur in the execution of the script (exactly the connection to the database), and return true if all goes well, or false otherwise. But I could not catch connection errors (For example, when too many connections
is generated, the script stops and does not return false). I read about set_handler_error
, but I do not know how to implement it.
Can anyone help me?