db.php (1575B)
1 <?php 2 /** 3 * @package OpenCart 4 * @author Daniel Kerr 5 * @copyright Copyright (c) 2005 - 2017, OpenCart, Ltd. (https://www.opencart.com/) 6 * @license https://opensource.org/licenses/GPL-3.0 7 * @link https://www.opencart.com 8 */ 9 10 /** 11 * DB class 12 */ 13 class DB { 14 private $adaptor; 15 16 /** 17 * Constructor 18 * 19 * @param string $adaptor 20 * @param string $hostname 21 * @param string $username 22 * @param string $password 23 * @param string $database 24 * @param int $port 25 * 26 */ 27 public function __construct($adaptor, $hostname, $username, $password, $database, $port = NULL) { 28 $class = 'DB\\' . $adaptor; 29 30 if (class_exists($class)) { 31 $this->adaptor = new $class($hostname, $username, $password, $database, $port); 32 } else { 33 throw new \Exception('Error: Could not load database adaptor ' . $adaptor . '!'); 34 } 35 } 36 37 /** 38 * 39 * 40 * @param string $sql 41 * 42 * @return array 43 */ 44 public function query($sql) { 45 return $this->adaptor->query($sql); 46 } 47 48 /** 49 * 50 * 51 * @param string $value 52 * 53 * @return string 54 */ 55 public function escape($value) { 56 return $this->adaptor->escape($value); 57 } 58 59 /** 60 * 61 * 62 * @return int 63 */ 64 public function countAffected() { 65 return $this->adaptor->countAffected(); 66 } 67 68 /** 69 * 70 * 71 * @return int 72 */ 73 public function getLastId() { 74 return $this->adaptor->getLastId(); 75 } 76 77 /** 78 * 79 * 80 * @return bool 81 */ 82 public function connected() { 83 return $this->adaptor->connected(); 84 } 85 }