|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* Copyright (C) 2024 Rafael San José <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software; you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU General Public License as published by |
|
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
8
|
|
|
* any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License |
|
16
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Dolibarr\Core\Base; |
|
20
|
|
|
|
|
21
|
|
|
use DebugBar\DebugBarException; |
|
22
|
|
|
use Illuminate\Database\Capsule\Manager as CapsuleManager; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a PDO database connection |
|
26
|
|
|
* |
|
27
|
|
|
* @package Alxarafe\Base |
|
28
|
|
|
*/ |
|
29
|
|
|
class Database extends CapsuleManager |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* Construct the database access |
|
33
|
|
|
* |
|
34
|
|
|
* @param $db |
|
35
|
|
|
* |
|
36
|
|
|
* @throws DebugBarException |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct() |
|
39
|
|
|
{ |
|
40
|
|
|
global $conf, $dolibarr_main_db_pass; |
|
41
|
|
|
|
|
42
|
|
|
$db = $conf->db; |
|
43
|
|
|
if ($db->type === 'mysqli') { |
|
44
|
|
|
$db->type = 'mysql'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
parent::__construct(); |
|
48
|
|
|
|
|
49
|
|
|
$this->addConnection([ |
|
50
|
|
|
'driver' => $db->type, |
|
51
|
|
|
'host' => $db->host, |
|
52
|
|
|
'database' => $db->name, |
|
53
|
|
|
'username' => $db->user, |
|
54
|
|
|
'password' => $dolibarr_main_db_pass, |
|
55
|
|
|
'charset' => $db->charset, |
|
56
|
|
|
'collation' => $db->collation, |
|
57
|
|
|
'prefix' => $db->prefix, |
|
58
|
|
|
]); |
|
59
|
|
|
|
|
60
|
|
|
$this->setAsGlobal(); |
|
61
|
|
|
$this->bootEloquent(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function getPdo() |
|
65
|
|
|
{ |
|
66
|
|
|
$static = new static(); |
|
67
|
|
|
return $static->getConnection()->getPdo(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|