NEW: Implementing dbConnect method, but it will be moved for other class.
This commit is contained in:
parent
ddf90ffeff
commit
19a07aa427
|
|
@ -1 +1,28 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
class ReportsModel
|
||||||
|
{
|
||||||
|
private $hostname = 'produs.linepbx.com.br';
|
||||||
|
private $username = 'produs-api';
|
||||||
|
private $password = '*Ingline.Sys#9420%SECURITY#';
|
||||||
|
private $database = 'qstats';
|
||||||
|
private static $connection = null;
|
||||||
|
|
||||||
|
public function __construct() {}
|
||||||
|
|
||||||
|
public function dbConnect()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (self::$connection === null) {
|
||||||
|
try {
|
||||||
|
self::$connection = new \PDO('mysql:host=produs.linepbx.com.br;dbname=qstats;charset=utf8mb4', $this->username, $this->password);
|
||||||
|
self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
return json_encode(['error' => 'Erro na conexão com o banco ' . $e->getMessage()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return self::$connection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue