Issues (32)

src/TraitDatabase.php (1 issue)

1
<?php
2
3
namespace Erykai\Database;
4
use PDO;
5
use PDOException;
6
7
/**
8
 * CLASS CONN
9
 */
10
trait TraitDatabase
11
{
12
    /**
13
     * @return PDO
14
     */
15
    private function conn(): PDO
16
    {
17
        if (empty($this->conn)) {
18
            try {
19
                $this->conn = new PDO(
0 ignored issues
show
Bug Best Practice introduced by
The property conn does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
                    CONN_DSN . ":host=" . CONN_HOST . ";dbname=" . CONN_BASE,
21
                    CONN_USER,
22
                    CONN_PASS,
23
                    [
24
                        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
25
                        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4"
26
                    ]
27
                );
28
            } catch (PDOException $e) {
29
                echo $e->getMessage() . " - in file " .
30
                    $e->getTrace()[1]['file'] . ' in line ' .
31
                    $e->getTrace()[1]['line'] . ' in function ' .
32
                    $e->getTrace()[1]['function'];
33
            }
34
        }
35
        return $this->conn;
36
    }
37
}