1: | <?php
2: | /**
3: | * @package OpenCart
4: | *
5: | * @author Daniel Kerr
6: | * @copyright Copyright (c) 2005 - 2022, OpenCart, Ltd. (https://www.opencart.com/)
7: | * @license https://opensource.org/licenses/GPL-3.0
8: | *
9: | * @see https://www.opencart.com
10: | */
11: | namespace Opencart\System\Library;
12: | /**
13: | * Class DB Adaptor
14: | *
15: | * @package Opencart\System\Library
16: | */
17: | class DB {
18: | /**
19: | * @var object
20: | */
21: | private object $adaptor;
22: |
23: | /**
24: | * Constructor
25: | *
26: | * @param string $adaptor
27: | * @param string $hostname
28: | * @param string $username
29: | * @param string $password
30: | * @param string $database
31: | * @param string $port
32: | * @param string $ssl_key
33: | * @param string $ssl_cert
34: | * @param string $ssl_ca
35: | */
36: | public function __construct(string $adaptor, string $hostname, string $username, string $password, string $database, string $port = '', string $ssl_key = '', string $ssl_cert = '', string $ssl_ca = '') {
37: | $class = 'Opencart\System\Library\DB\\' . $adaptor;
38: |
39: | if (class_exists($class)) {
40: | $this->adaptor = new $class($hostname, $username, $password, $database, $port, $ssl_key, $ssl_cert, $ssl_ca);
41: | } else {
42: | throw new \Exception('Error: Could not load database adaptor ' . $adaptor . '!');
43: | }
44: | }
45: |
46: | /**
47: | * Query
48: | *
49: | * @param string $sql SQL statement to be executed
50: | *
51: | * @return mixed
52: | */
53: | public function query(string $sql) {
54: | return $this->adaptor->query($sql);
55: | }
56: |
57: | /**
58: | * Escape
59: | *
60: | * @param string $value Value to be protected against SQL injections
61: | *
62: | * @return string Returns escaped value
63: | */
64: | public function escape(string $value): string {
65: | return $this->adaptor->escape($value);
66: | }
67: |
68: | /**
69: | * countAffected
70: | *
71: | * Gets the total number of affected rows from the last query
72: | *
73: | * @return int returns the total number of affected rows
74: | */
75: | public function countAffected(): int {
76: | return $this->adaptor->countAffected();
77: | }
78: |
79: | /**
80: | * getLastId
81: | *
82: | * Get the last ID gets the primary key that was returned after creating a row in a table.
83: | *
84: | * @return int Returns last ID
85: | */
86: | public function getLastId(): int {
87: | return $this->adaptor->getLastId();
88: | }
89: |
90: | /**
91: | * isConnected
92: | *
93: | * Checks if a DB connection is active.
94: | *
95: | * @return bool
96: | */
97: | public function isConnected(): bool {
98: | return $this->adaptor->isConnected();
99: | }
100: | }
101: |

OpenCart API API documentation generated by ApiGen dev-master