Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\core\libs;
- use Illuminate\Database\Capsule\Manager;
- use PHPMailer\PHPMailer\Exception;
- use PHPMailer\PHPMailer\PHPMailer;
- class DBManager
- {
- protected static $manger;
- public static function init()
- {
- self::notificaError("asds");
- dd('enviado');
- try {
- new \Exception("Prueba de notificación de exceptiones - guegue");
- self::$manger = new Manager();
- self::$manger->addConnection([
- 'driver' => DRIVER,
- 'host' => DB_HOST,
- 'database' => DB_NAME,
- 'username' => DB_USER,
- 'password' => DB_PASSWORD,
- 'charset' => CHARSET,
- 'collation' => COLLATION,
- 'prefix' => PREFIX,
- ]);
- self::$manger->setAsGlobal();
- self::$manger->bootEloquent();
- } catch (\Exception $e) {
- self::notificaError($e);
- }
- }
- public static function getConnection()
- {
- try {
- return self::$manger->getConnection();
- } catch (\Exception $e){
- self::notificaError($e);
- }
- }
- public static function beginTransaction()
- {
- try {
- self::getConnection()->beginTransaction();
- } catch (\Exception $e){
- self::notificaError($e);
- }
- }
- public static function commit()
- {
- try {
- self::getConnection()->commit();
- } catch (\Exception $e){
- self::notificaError($e);
- }
- }
- public static function rollBack()
- {
- try {
- self::getConnection()->rollback();
- } catch (\Exception $e){
- self::notificaError($e);
- }
- }
- public static function self()
- {
- return self::$manger;
- }
- public static function notificaError($excepcion){
- /*Configuración*/
- $ruta = $_SERVER['PHP_SELF'];
- $ip = $_SERVER['REMOTE_ADDR'];
- $cliente = gethostbyaddr($_SERVER['REMOTE_ADDR']);
- $file = basename($ruta);
- $fecha = date('d/m/Y H:m:s');
- $msg_enviar = "<h2><u>Error en: Desarrollo</u></h2>";
- $msg_enviar .="<u>Fallo la consulta a la base de datos</u><br />";
- $msg_enviar .= "<u>Fecha del error</u>: {$fecha} <br />";
- $msg_enviar .= "<u>URL del error</u>: {$ruta}<br />";
- $msg_enviar .= "<u>Archivo</u>: {$file}<br />";
- $msg_enviar .= "<u>IP</u>: {$ip}<br />";
- $msg_enviar .= "<u>Nombre de la PC del usuario</u>: {$cliente}<br />";
- $msg_enviar .= "<u>Descripción</u>: <br />";
- $msg_enviar .= str_replace("\r\n", "<br />", $excepcion);
- /*Correos*/
- $obj_mail = new PHPMailer();
- $obj_mail->Mailer = "smtp";
- $obj_mail->Host = "mail.inatec.edu.ni";
- $obj_mail->From = "INATEC";
- $obj_mail->FromName = "INATEC - PRODUCCIÓN";
- $obj_mail->Timeout = 30;
- $obj_mail->AddAddress("adalgarcia17@gmail.com");
- $obj_mail->Subject = "Error en el Sistema";
- $obj_mail->Body = $msg_enviar;
- $obj_mail->IsHTML(true);
- $obj_mail->Send();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement