106 lines
1.9 KiB
PHP
106 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package OpenCart
|
|
* @author Daniel Kerr
|
|
* @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/)
|
|
* @license https://opensource.org/licenses/GPL-3.0
|
|
* @link https://www.opencart.com
|
|
*/
|
|
|
|
declare(strict_types = 1);
|
|
|
|
namespace Database;
|
|
|
|
use RuntimeException;
|
|
|
|
/**
|
|
* DB class
|
|
*/
|
|
class DB
|
|
{
|
|
private mixed $adaptor;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param string $adaptor
|
|
* @param string $hostname
|
|
* @param string $username
|
|
* @param string $password
|
|
* @param string $database
|
|
* @param int|null $port
|
|
*
|
|
*/
|
|
public function __construct(
|
|
string $adaptor,
|
|
string $hostname,
|
|
string $username,
|
|
string $password,
|
|
string $database,
|
|
int $port = null
|
|
) {
|
|
$class = 'DB\\' . $adaptor;
|
|
|
|
if (class_exists($class)) {
|
|
$this->adaptor = new $class($hostname, $username, $password, $database, $port);
|
|
} else {
|
|
throw new RuntimeException('Error: Could not load database adaptor ' . $adaptor . '!');
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @param string $sql
|
|
*
|
|
* @return array
|
|
*/
|
|
public function query(string $sql): array
|
|
{
|
|
return $this->adaptor->query($sql);
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @param string $value
|
|
*
|
|
* @return string
|
|
*/
|
|
public function escape(string $value): string
|
|
{
|
|
return $this->adaptor->escape($value);
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @return int
|
|
*/
|
|
public function countAffected(): int
|
|
{
|
|
return $this->adaptor->countAffected();
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @return int
|
|
*/
|
|
public function getLastId(): int
|
|
{
|
|
return $this->adaptor->getLastId();
|
|
}
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function connected(): bool
|
|
{
|
|
return $this->adaptor->connected();
|
|
}
|
|
}
|