Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Db / Adapter / Platform / Mysql.php
blob3b16f260e46523c2faf03d364ddfa6f565cb9b5f
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Db\Adapter\Platform;
12 use Zend\Db\Adapter\Driver\DriverInterface;
13 use Zend\Db\Adapter\Driver\Mysqli;
14 use Zend\Db\Adapter\Driver\Pdo;
15 use Zend\Db\Adapter\Exception;
17 class Mysql implements PlatformInterface
19 /** @var \mysqli|\PDO */
20 protected $resource = null;
22 public function __construct($driver = null)
24 if ($driver) {
25 $this->setDriver($driver);
29 /**
30 * @param \Zend\Db\Adapter\Driver\Mysqli\Mysqli|\Zend\Db\Adapter\Driver\Pdo\Pdo||\mysqli|\PDO $driver
31 * @throws \Zend\Db\Adapter\Exception\InvalidArgumentException
32 * @return $this
34 public function setDriver($driver)
36 // handle Zend\Db drivers
37 if ($driver instanceof Mysqli\Mysqli
38 || ($driver instanceof Pdo\Pdo && $driver->getDatabasePlatformName() == 'Mysql')
39 || ($driver instanceof \mysqli)
40 || ($driver instanceof \PDO && $driver->getAttribute(\PDO::ATTR_DRIVER_NAME) == 'mysql')
41 ) {
42 $this->resource = $driver;
43 return $this;
46 throw new Exception\InvalidArgumentException('$driver must be a Mysqli or Mysql PDO Zend\Db\Adapter\Driver, Mysqli instance or MySQL PDO instance');
49 /**
50 * Get name
52 * @return string
54 public function getName()
56 return 'MySQL';
59 /**
60 * Get quote identifier symbol
62 * @return string
64 public function getQuoteIdentifierSymbol()
66 return '`';
69 /**
70 * Quote identifier
72 * @param string $identifier
73 * @return string
75 public function quoteIdentifier($identifier)
77 return '`' . str_replace('`', '``', $identifier) . '`';
80 /**
81 * Quote identifier chain
83 * @param string|string[] $identifierChain
84 * @return string
86 public function quoteIdentifierChain($identifierChain)
88 $identifierChain = str_replace('`', '``', $identifierChain);
89 if (is_array($identifierChain)) {
90 $identifierChain = implode('`.`', $identifierChain);
92 return '`' . $identifierChain . '`';
95 /**
96 * Get quote value symbol
98 * @return string
100 public function getQuoteValueSymbol()
102 return '\'';
106 * Quote value
108 * @param string $value
109 * @return string
111 public function quoteValue($value)
113 if ($this->resource instanceof DriverInterface) {
114 $this->resource = $this->resource->getConnection()->getResource();
116 if ($this->resource instanceof \mysqli) {
117 return '\'' . $this->resource->real_escape_string($value) . '\'';
119 if ($this->resource instanceof \PDO) {
120 return $this->resource->quote($value);
122 trigger_error(
123 'Attempting to quote a value in ' . __CLASS__ . ' without extension/driver support '
124 . 'can introduce security vulnerabilities in a production environment.'
126 return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\'';
130 * Quote Trusted Value
132 * The ability to quote values without notices
134 * @param $value
135 * @return mixed
137 public function quoteTrustedValue($value)
139 if ($this->resource instanceof DriverInterface) {
140 $this->resource = $this->resource->getConnection()->getResource();
142 if ($this->resource instanceof \mysqli) {
143 return '\'' . $this->resource->real_escape_string($value) . '\'';
145 if ($this->resource instanceof \PDO) {
146 return $this->resource->quote($value);
148 return '\'' . addcslashes($value, "\x00\n\r\\'\"\x1a") . '\'';
152 * Quote value list
154 * @param string|string[] $valueList
155 * @return string
157 public function quoteValueList($valueList)
159 if (!is_array($valueList)) {
160 return $this->quoteValue($valueList);
163 $value = reset($valueList);
164 do {
165 $valueList[key($valueList)] = $this->quoteValue($value);
166 } while ($value = next($valueList));
167 return implode(', ', $valueList);
171 * Get identifier separator
173 * @return string
175 public function getIdentifierSeparator()
177 return '.';
181 * Quote identifier in fragment
183 * @param string $identifier
184 * @param array $safeWords
185 * @return string
187 public function quoteIdentifierInFragment($identifier, array $safeWords = array())
189 // regex taken from @link http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
190 $parts = preg_split('#([^0-9,a-z,A-Z$_])#', $identifier, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
191 if ($safeWords) {
192 $safeWords = array_flip($safeWords);
193 $safeWords = array_change_key_case($safeWords, CASE_LOWER);
195 foreach ($parts as $i => $part) {
196 if ($safeWords && isset($safeWords[strtolower($part)])) {
197 continue;
199 switch ($part) {
200 case ' ':
201 case '.':
202 case '*':
203 case 'AS':
204 case 'As':
205 case 'aS':
206 case 'as':
207 break;
208 default:
209 $parts[$i] = '`' . str_replace('`', '``', $part) . '`';
212 return implode('', $parts);