PageRenderTime 61ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/common/libraries/plugin/pear/MDB2/Driver/mysqli.php

https://bitbucket.org/gugli/chamilo-dev
PHP | 2043 lines | 1329 code | 187 blank | 527 comment | 232 complexity | 6453067155dacf7c4e23d7e0e1b5b5d7 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, LGPL-3.0, GPL-3.0, MIT, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP versions 4 and 5 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox, |
  7. // | Stig. S. Bakken, Lukas Smith |
  8. // | All rights reserved. |
  9. // +----------------------------------------------------------------------+
  10. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB |
  11. // | API as well as database abstraction for PHP applications. |
  12. // | This LICENSE is in the BSD license style. |
  13. // | |
  14. // | Redistribution and use in source and binary forms, with or without |
  15. // | modification, are permitted provided that the following conditions |
  16. // | are met: |
  17. // | |
  18. // | Redistributions of source code must retain the above copyright |
  19. // | notice, this list of conditions and the following disclaimer. |
  20. // | |
  21. // | Redistributions in binary form must reproduce the above copyright |
  22. // | notice, this list of conditions and the following disclaimer in the |
  23. // | documentation and/or other materials provided with the distribution. |
  24. // | |
  25. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
  26. // | Lukas Smith nor the names of his contributors may be used to endorse |
  27. // | or promote products derived from this software without specific prior|
  28. // | written permission. |
  29. // | |
  30. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  31. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  32. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
  33. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
  34. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
  35. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37. // | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
  38. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
  39. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
  41. // | POSSIBILITY OF SUCH DAMAGE. |
  42. // +----------------------------------------------------------------------+
  43. // | Author: Lukas Smith <smith@pooteeweet.org> |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: mysqli.php 137 2009-11-09 13:24:37Z vanpouckesven $
  47. //
  48. /**
  49. * MDB2 MySQLi driver
  50. *
  51. * @package MDB2
  52. * @category Database
  53. * @author Lukas Smith <smith@pooteeweet.org>
  54. */
  55. class MDB2_Driver_mysqli extends MDB2_Driver_Common
  56. {
  57. // {{{ properties
  58. var $string_quoting = array('start' => "'", 'end' => "'", 'escape' => '\\', 'escape_pattern' => '\\');
  59. var $identifier_quoting = array('start' => '`', 'end' => '`', 'escape' => '`');
  60. var $sql_comments = array(array('start' => '-- ', 'end' => "\n", 'escape' => false),
  61. array('start' => '#', 'end' => "\n", 'escape' => false),
  62. array('start' => '/*', 'end' => '*/', 'escape' => false));
  63. var $server_capabilities_checked = false;
  64. var $start_transaction = false;
  65. var $varchar_max_length = 255;
  66. // }}}
  67. // {{{ constructor
  68. /**
  69. * Constructor
  70. */
  71. function __construct()
  72. {
  73. parent :: __construct();
  74. $this->phptype = 'mysqli';
  75. $this->dbsyntax = 'mysql';
  76. $this->supported['sequences'] = 'emulated';
  77. $this->supported['indexes'] = true;
  78. $this->supported['affected_rows'] = true;
  79. $this->supported['transactions'] = false;
  80. $this->supported['savepoints'] = false;
  81. $this->supported['summary_functions'] = true;
  82. $this->supported['order_by_text'] = true;
  83. $this->supported['current_id'] = 'emulated';
  84. $this->supported['limit_queries'] = true;
  85. $this->supported['LOBs'] = true;
  86. $this->supported['replace'] = true;
  87. $this->supported['sub_selects'] = 'emulated';
  88. $this->supported['triggers'] = false;
  89. $this->supported['auto_increment'] = true;
  90. $this->supported['primary_key'] = true;
  91. $this->supported['result_introspection'] = true;
  92. $this->supported['prepared_statements'] = 'emulated';
  93. $this->supported['identifier_quoting'] = true;
  94. $this->supported['pattern_escaping'] = true;
  95. $this->supported['new_link'] = true;
  96. $this->options['DBA_username'] = false;
  97. $this->options['DBA_password'] = false;
  98. $this->options['default_table_type'] = '';
  99. $this->options['multi_query'] = false;
  100. $this->options['max_identifiers_length'] = 64;
  101. $this->_reCheckSupportedOptions();
  102. }
  103. // }}}
  104. // {{{ _reCheckSupportedOptions()
  105. /**
  106. * If the user changes certain options, other capabilities may depend
  107. * on the new settings, so we need to check them (again).
  108. *
  109. * @access private
  110. */
  111. function _reCheckSupportedOptions()
  112. {
  113. $this->supported['transactions'] = $this->options['use_transactions'];
  114. $this->supported['savepoints'] = $this->options['use_transactions'];
  115. if ($this->options['default_table_type'])
  116. {
  117. switch (strtoupper($this->options['default_table_type']))
  118. {
  119. case 'BLACKHOLE' :
  120. case 'MEMORY' :
  121. case 'ARCHIVE' :
  122. case 'CSV' :
  123. case 'HEAP' :
  124. case 'ISAM' :
  125. case 'MERGE' :
  126. case 'MRG_ISAM' :
  127. case 'ISAM' :
  128. case 'MRG_MYISAM' :
  129. case 'MYISAM' :
  130. $this->supported['savepoints'] = false;
  131. $this->supported['transactions'] = false;
  132. $this->warnings[] = $this->options['default_table_type'] . ' is not a supported default table type';
  133. break;
  134. }
  135. }
  136. }
  137. // }}}
  138. // {{{ function setOption($option, $value)
  139. /**
  140. * set the option for the db class
  141. *
  142. * @param string option name
  143. * @param mixed value for the option
  144. *
  145. * @return mixed MDB2_OK or MDB2 Error Object
  146. *
  147. * @access public
  148. */
  149. function setOption($option, $value)
  150. {
  151. $res = parent :: setOption($option, $value);
  152. $this->_reCheckSupportedOptions();
  153. }
  154. // }}}
  155. // {{{ errorInfo()
  156. /**
  157. * This method is used to collect information about an error
  158. *
  159. * @param integer $error
  160. * @return array
  161. * @access public
  162. */
  163. function errorInfo($error = null)
  164. {
  165. if ($this->connection)
  166. {
  167. $native_code = @mysqli_errno($this->connection);
  168. $native_msg = @mysqli_error($this->connection);
  169. }
  170. else
  171. {
  172. $native_code = @mysqli_connect_errno();
  173. $native_msg = @mysqli_connect_error();
  174. }
  175. if (is_null($error))
  176. {
  177. static $ecode_map;
  178. if (empty($ecode_map))
  179. {
  180. $ecode_map = array(1000 => MDB2_ERROR_INVALID, //hashchk
  181. 1001 => MDB2_ERROR_INVALID, //isamchk
  182. 1004 => MDB2_ERROR_CANNOT_CREATE, 1005 => MDB2_ERROR_CANNOT_CREATE,
  183. 1006 => MDB2_ERROR_CANNOT_CREATE, 1007 => MDB2_ERROR_ALREADY_EXISTS,
  184. 1008 => MDB2_ERROR_CANNOT_DROP, 1009 => MDB2_ERROR_CANNOT_DROP, 1010 => MDB2_ERROR_CANNOT_DROP,
  185. 1011 => MDB2_ERROR_CANNOT_DELETE, 1022 => MDB2_ERROR_ALREADY_EXISTS,
  186. 1029 => MDB2_ERROR_NOT_FOUND, 1032 => MDB2_ERROR_NOT_FOUND, 1044 => MDB2_ERROR_ACCESS_VIOLATION,
  187. 1045 => MDB2_ERROR_ACCESS_VIOLATION, 1046 => MDB2_ERROR_NODBSELECTED,
  188. 1048 => MDB2_ERROR_CONSTRAINT, 1049 => MDB2_ERROR_NOSUCHDB, 1050 => MDB2_ERROR_ALREADY_EXISTS,
  189. 1051 => MDB2_ERROR_NOSUCHTABLE, 1054 => MDB2_ERROR_NOSUCHFIELD,
  190. 1060 => MDB2_ERROR_ALREADY_EXISTS, 1061 => MDB2_ERROR_ALREADY_EXISTS,
  191. 1062 => MDB2_ERROR_ALREADY_EXISTS, 1064 => MDB2_ERROR_SYNTAX, 1067 => MDB2_ERROR_INVALID,
  192. 1072 => MDB2_ERROR_NOT_FOUND, 1086 => MDB2_ERROR_ALREADY_EXISTS, 1091 => MDB2_ERROR_NOT_FOUND,
  193. 1100 => MDB2_ERROR_NOT_LOCKED, 1109 => MDB2_ERROR_NOT_FOUND, 1125 => MDB2_ERROR_ALREADY_EXISTS,
  194. 1136 => MDB2_ERROR_VALUE_COUNT_ON_ROW, 1138 => MDB2_ERROR_INVALID,
  195. 1142 => MDB2_ERROR_ACCESS_VIOLATION, 1143 => MDB2_ERROR_ACCESS_VIOLATION,
  196. 1146 => MDB2_ERROR_NOSUCHTABLE, 1149 => MDB2_ERROR_SYNTAX, 1169 => MDB2_ERROR_CONSTRAINT,
  197. 1176 => MDB2_ERROR_NOT_FOUND, 1177 => MDB2_ERROR_NOSUCHTABLE, 1213 => MDB2_ERROR_DEADLOCK,
  198. 1216 => MDB2_ERROR_CONSTRAINT, 1217 => MDB2_ERROR_CONSTRAINT,
  199. 1227 => MDB2_ERROR_ACCESS_VIOLATION, 1235 => MDB2_ERROR_CANNOT_CREATE,
  200. 1299 => MDB2_ERROR_INVALID_DATE, 1300 => MDB2_ERROR_INVALID, 1304 => MDB2_ERROR_ALREADY_EXISTS,
  201. 1305 => MDB2_ERROR_NOT_FOUND, 1306 => MDB2_ERROR_CANNOT_DROP, 1307 => MDB2_ERROR_CANNOT_CREATE,
  202. 1334 => MDB2_ERROR_CANNOT_ALTER, 1339 => MDB2_ERROR_NOT_FOUND, 1356 => MDB2_ERROR_INVALID,
  203. 1359 => MDB2_ERROR_ALREADY_EXISTS, 1360 => MDB2_ERROR_NOT_FOUND, 1363 => MDB2_ERROR_NOT_FOUND,
  204. 1365 => MDB2_ERROR_DIVZERO, 1451 => MDB2_ERROR_CONSTRAINT, 1452 => MDB2_ERROR_CONSTRAINT,
  205. 1542 => MDB2_ERROR_CANNOT_DROP, 1546 => MDB2_ERROR_CONSTRAINT, 1582 => MDB2_ERROR_CONSTRAINT,
  206. 2003 => MDB2_ERROR_CONNECT_FAILED, 2019 => MDB2_ERROR_INVALID);
  207. }
  208. if ($this->options['portability'] & MDB2_PORTABILITY_ERRORS)
  209. {
  210. $ecode_map[1022] = MDB2_ERROR_CONSTRAINT;
  211. $ecode_map[1048] = MDB2_ERROR_CONSTRAINT_NOT_NULL;
  212. $ecode_map[1062] = MDB2_ERROR_CONSTRAINT;
  213. }
  214. else
  215. {
  216. // Doing this in case mode changes during runtime.
  217. $ecode_map[1022] = MDB2_ERROR_ALREADY_EXISTS;
  218. $ecode_map[1048] = MDB2_ERROR_CONSTRAINT;
  219. $ecode_map[1062] = MDB2_ERROR_ALREADY_EXISTS;
  220. }
  221. if (isset($ecode_map[$native_code]))
  222. {
  223. $error = $ecode_map[$native_code];
  224. }
  225. }
  226. return array($error, $native_code, $native_msg);
  227. }
  228. // }}}
  229. // {{{ escape()
  230. /**
  231. * Quotes a string so it can be safely used in a query. It will quote
  232. * the text so it can safely be used within a query.
  233. *
  234. * @param string the input string to quote
  235. * @param bool escape wildcards
  236. *
  237. * @return string quoted string
  238. *
  239. * @access public
  240. */
  241. function escape($text, $escape_wildcards = false)
  242. {
  243. if ($escape_wildcards)
  244. {
  245. $text = $this->escapePattern($text);
  246. }
  247. $connection = $this->getConnection();
  248. if (PEAR :: isError($connection))
  249. {
  250. return $connection;
  251. }
  252. $text = @mysqli_real_escape_string($connection, $text);
  253. return $text;
  254. }
  255. // }}}
  256. // {{{ beginTransaction()
  257. /**
  258. * Start a transaction or set a savepoint.
  259. *
  260. * @param string name of a savepoint to set
  261. * @return mixed MDB2_OK on success, a MDB2 error on failure
  262. *
  263. * @access public
  264. */
  265. function beginTransaction($savepoint = null)
  266. {
  267. $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true,
  268. 'savepoint' => $savepoint));
  269. $this->_getServerCapabilities();
  270. if (! is_null($savepoint))
  271. {
  272. if (! $this->supports('savepoints'))
  273. {
  274. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'savepoints are not supported', __FUNCTION__);
  275. }
  276. if (! $this->in_transaction)
  277. {
  278. return $this->raiseError(MDB2_ERROR_INVALID, null, null, 'savepoint cannot be released when changes are auto committed', __FUNCTION__);
  279. }
  280. $query = 'SAVEPOINT ' . $savepoint;
  281. return $this->_doQuery($query, true);
  282. }
  283. elseif ($this->in_transaction)
  284. {
  285. return MDB2_OK; //nothing to do
  286. }
  287. $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0';
  288. $result = & $this->_doQuery($query, true);
  289. if (PEAR :: isError($result))
  290. {
  291. return $result;
  292. }
  293. $this->in_transaction = true;
  294. return MDB2_OK;
  295. }
  296. // }}}
  297. // {{{ commit()
  298. /**
  299. * Commit the database changes done during a transaction that is in
  300. * progress or release a savepoint. This function may only be called when
  301. * auto-committing is disabled, otherwise it will fail. Therefore, a new
  302. * transaction is implicitly started after committing the pending changes.
  303. *
  304. * @param string name of a savepoint to release
  305. * @return mixed MDB2_OK on success, a MDB2 error on failure
  306. *
  307. * @access public
  308. */
  309. function commit($savepoint = null)
  310. {
  311. $this->debug('Committing transaction/savepoint', __FUNCTION__, array('is_manip' => true,
  312. 'savepoint' => $savepoint));
  313. if (! $this->in_transaction)
  314. {
  315. return $this->raiseError(MDB2_ERROR_INVALID, null, null, 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__);
  316. }
  317. if (! is_null($savepoint))
  318. {
  319. if (! $this->supports('savepoints'))
  320. {
  321. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'savepoints are not supported', __FUNCTION__);
  322. }
  323. $server_info = $this->getServerVersion();
  324. if (version_compare($server_info['major'] . '.' . $server_info['minor'] . '.' . $server_info['patch'], '5.0.3', '<'))
  325. {
  326. return MDB2_OK;
  327. }
  328. $query = 'RELEASE SAVEPOINT ' . $savepoint;
  329. return $this->_doQuery($query, true);
  330. }
  331. if (! $this->supports('transactions'))
  332. {
  333. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'transactions are not supported', __FUNCTION__);
  334. }
  335. $result = & $this->_doQuery('COMMIT', true);
  336. if (PEAR :: isError($result))
  337. {
  338. return $result;
  339. }
  340. if (! $this->start_transaction)
  341. {
  342. $query = 'SET AUTOCOMMIT = 1';
  343. $result = & $this->_doQuery($query, true);
  344. if (PEAR :: isError($result))
  345. {
  346. return $result;
  347. }
  348. }
  349. $this->in_transaction = false;
  350. return MDB2_OK;
  351. }
  352. // }}}
  353. // {{{ rollback()
  354. /**
  355. * Cancel any database changes done during a transaction or since a specific
  356. * savepoint that is in progress. This function may only be called when
  357. * auto-committing is disabled, otherwise it will fail. Therefore, a new
  358. * transaction is implicitly started after canceling the pending changes.
  359. *
  360. * @param string name of a savepoint to rollback to
  361. * @return mixed MDB2_OK on success, a MDB2 error on failure
  362. *
  363. * @access public
  364. */
  365. function rollback($savepoint = null)
  366. {
  367. $this->debug('Rolling back transaction/savepoint', __FUNCTION__, array('is_manip' => true,
  368. 'savepoint' => $savepoint));
  369. if (! $this->in_transaction)
  370. {
  371. return $this->raiseError(MDB2_ERROR_INVALID, null, null, 'rollback cannot be done changes are auto committed', __FUNCTION__);
  372. }
  373. if (! is_null($savepoint))
  374. {
  375. if (! $this->supports('savepoints'))
  376. {
  377. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'savepoints are not supported', __FUNCTION__);
  378. }
  379. $query = 'ROLLBACK TO SAVEPOINT ' . $savepoint;
  380. return $this->_doQuery($query, true);
  381. }
  382. $query = 'ROLLBACK';
  383. $result = & $this->_doQuery($query, true);
  384. if (PEAR :: isError($result))
  385. {
  386. return $result;
  387. }
  388. if (! $this->start_transaction)
  389. {
  390. $query = 'SET AUTOCOMMIT = 1';
  391. $result = & $this->_doQuery($query, true);
  392. if (PEAR :: isError($result))
  393. {
  394. return $result;
  395. }
  396. }
  397. $this->in_transaction = false;
  398. return MDB2_OK;
  399. }
  400. // }}}
  401. // {{{ function setTransactionIsolation()
  402. /**
  403. * Set the transacton isolation level.
  404. *
  405. * @param string standard isolation level
  406. * READ UNCOMMITTED (allows dirty reads)
  407. * READ COMMITTED (prevents dirty reads)
  408. * REPEATABLE READ (prevents nonrepeatable reads)
  409. * SERIALIZABLE (prevents phantom reads)
  410. * @return mixed MDB2_OK on success, a MDB2 error on failure
  411. *
  412. * @access public
  413. * @since 2.1.1
  414. */
  415. function setTransactionIsolation($isolation)
  416. {
  417. $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true));
  418. if (! $this->supports('transactions'))
  419. {
  420. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'transactions are not supported', __FUNCTION__);
  421. }
  422. switch ($isolation)
  423. {
  424. case 'READ UNCOMMITTED' :
  425. case 'READ COMMITTED' :
  426. case 'REPEATABLE READ' :
  427. case 'SERIALIZABLE' :
  428. break;
  429. default :
  430. return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, 'isolation level is not supported: ' . $isolation, __FUNCTION__);
  431. }
  432. $query = "SET SESSION TRANSACTION ISOLATION LEVEL $isolation";
  433. return $this->_doQuery($query, true);
  434. }
  435. // }}}
  436. // {{{ _doConnect()
  437. /**
  438. * do the grunt work of the connect
  439. *
  440. * @return connection on success or MDB2 Error Object on failure
  441. * @access protected
  442. */
  443. function _doConnect($username, $password, $persistent = false)
  444. {
  445. if (! PEAR :: loadExtension($this->phptype))
  446. {
  447. return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'extension ' . $this->phptype . ' is not compiled into PHP', __FUNCTION__);
  448. }
  449. $connection = @mysqli_init();
  450. if (! empty($this->dsn['charset']) && defined('MYSQLI_SET_CHARSET_NAME'))
  451. {
  452. @mysqli_options($connection, MYSQLI_SET_CHARSET_NAME, $this->dsn['charset']);
  453. }
  454. if ($this->options['ssl'])
  455. {
  456. @mysqli_ssl_set($connection, empty($this->dsn['key']) ? null : $this->dsn['key'], empty($this->dsn['cert']) ? null : $this->dsn['cert'], empty($this->dsn['ca']) ? null : $this->dsn['ca'], empty($this->dsn['capath']) ? null : $this->dsn['capath'], empty($this->dsn['cipher']) ? null : $this->dsn['cipher']);
  457. }
  458. if (! @mysqli_real_connect($connection, $this->dsn['hostspec'], $username, $password, $this->database_name, $this->dsn['port'], $this->dsn['socket']))
  459. {
  460. if (($err = @mysqli_connect_error()) != '')
  461. {
  462. return $this->raiseError(null, null, null, $err, __FUNCTION__);
  463. }
  464. else
  465. {
  466. return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, 'unable to establish a connection', __FUNCTION__);
  467. }
  468. }
  469. if (! empty($this->dsn['charset']) && ! defined('MYSQLI_SET_CHARSET_NAME'))
  470. {
  471. $result = $this->setCharset($this->dsn['charset'], $connection);
  472. if (PEAR :: isError($result))
  473. {
  474. return $result;
  475. }
  476. }
  477. return $connection;
  478. }
  479. // }}}
  480. // {{{ connect()
  481. /**
  482. * Connect to the database
  483. *
  484. * @return true on success, MDB2 Error Object on failure
  485. */
  486. function connect()
  487. {
  488. if (is_object($this->connection))
  489. {
  490. if (count(array_diff($this->connected_dsn, $this->dsn)) == 0)
  491. {
  492. //if (MDB2::areEquals($this->connected_dsn, $this->dsn)) { //memory leak fixed, so no need for heavier areEquals function
  493. return MDB2_OK;
  494. }
  495. $this->connection = 0;
  496. }
  497. $connection = $this->_doConnect($this->dsn['username'], $this->dsn['password']);
  498. if (PEAR :: isError($connection))
  499. {
  500. return $connection;
  501. }
  502. $this->connection = $connection;
  503. $this->connected_dsn = $this->dsn;
  504. $this->connected_database_name = $this->database_name;
  505. $this->dbsyntax = $this->dsn['dbsyntax'] ? $this->dsn['dbsyntax'] : $this->phptype;
  506. $this->_getServerCapabilities();
  507. return MDB2_OK;
  508. }
  509. // }}}
  510. // {{{ setCharset()
  511. /**
  512. * Set the charset on the current connection
  513. *
  514. * @param string charset (or array(charset, collation))
  515. * @param resource connection handle
  516. *
  517. * @return true on success, MDB2 Error Object on failure
  518. */
  519. function setCharset($charset, $connection = null)
  520. {
  521. if (is_null($connection))
  522. {
  523. $connection = $this->getConnection();
  524. if (PEAR :: isError($connection))
  525. {
  526. return $connection;
  527. }
  528. }
  529. $collation = null;
  530. if (is_array($charset) && 2 == count($charset))
  531. {
  532. $collation = array_pop($charset);
  533. $charset = array_pop($charset);
  534. }
  535. $client_info = mysqli_get_client_version();
  536. if (OS_WINDOWS && ((40111 > $client_info) || ((50000 <= $client_info) && (50006 > $client_info))))
  537. {
  538. $query = "SET NAMES '" . mysqli_real_escape_string($connection, $charset) . "'";
  539. if (! is_null($collation))
  540. {
  541. $query .= " COLLATE '" . mysqli_real_escape_string($connection, $collation) . "'";
  542. }
  543. return $this->_doQuery($query, true, $connection);
  544. }
  545. if (! $result = mysqli_set_charset($connection, $charset))
  546. {
  547. $err = & $this->raiseError(null, null, null, 'Could not set client character set', __FUNCTION__);
  548. return $err;
  549. }
  550. return $result;
  551. }
  552. // }}}
  553. // {{{ databaseExists()
  554. /**
  555. * check if given database name is exists?
  556. *
  557. * @param string $name name of the database that should be checked
  558. *
  559. * @return mixed true/false on success, a MDB2 error on failure
  560. * @access public
  561. */
  562. function databaseExists($name)
  563. {
  564. $connection = $this->_doConnect($this->dsn['username'], $this->dsn['password']);
  565. if (PEAR :: isError($connection))
  566. {
  567. return $connection;
  568. }
  569. $result = @mysqli_select_db($connection, $name);
  570. @mysqli_close($connection);
  571. return $result;
  572. }
  573. // }}}
  574. // {{{ disconnect()
  575. /**
  576. * Log out and disconnect from the database.
  577. *
  578. * @param boolean $force if the disconnect should be forced even if the
  579. * connection is opened persistently
  580. * @return mixed true on success, false if not connected and error
  581. * object on error
  582. * @access public
  583. */
  584. function disconnect($force = true)
  585. {
  586. if (is_object($this->connection))
  587. {
  588. if ($this->in_transaction)
  589. {
  590. $dsn = $this->dsn;
  591. $database_name = $this->database_name;
  592. $persistent = $this->options['persistent'];
  593. $this->dsn = $this->connected_dsn;
  594. $this->database_name = $this->connected_database_name;
  595. $this->options['persistent'] = $this->opened_persistent;
  596. $this->rollback();
  597. $this->dsn = $dsn;
  598. $this->database_name = $database_name;
  599. $this->options['persistent'] = $persistent;
  600. }
  601. if ($force)
  602. {
  603. $ok = @mysqli_close($this->connection);
  604. if (! $ok)
  605. {
  606. return $this->raiseError(MDB2_ERROR_DISCONNECT_FAILED, null, null, null, __FUNCTION__);
  607. }
  608. }
  609. }
  610. else
  611. {
  612. return false;
  613. }
  614. return parent :: disconnect($force);
  615. }
  616. // }}}
  617. // {{{ standaloneQuery()
  618. /**
  619. * execute a query as DBA
  620. *
  621. * @param string $query the SQL query
  622. * @param mixed $types array that contains the types of the columns in
  623. * the result set
  624. * @param boolean $is_manip if the query is a manipulation query
  625. * @return mixed MDB2_OK on success, a MDB2 error on failure
  626. * @access public
  627. */
  628. function &standaloneQuery($query, $types = null, $is_manip = false)
  629. {
  630. $user = $this->options['DBA_username'] ? $this->options['DBA_username'] : $this->dsn['username'];
  631. $pass = $this->options['DBA_password'] ? $this->options['DBA_password'] : $this->dsn['password'];
  632. $connection = $this->_doConnect($user, $pass);
  633. if (PEAR :: isError($connection))
  634. {
  635. return $connection;
  636. }
  637. $offset = $this->offset;
  638. $limit = $this->limit;
  639. $this->offset = $this->limit = 0;
  640. $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
  641. $result = & $this->_doQuery($query, $is_manip, $connection, $this->database_name);
  642. if (! PEAR :: isError($result))
  643. {
  644. $result = $this->_affectedRows($connection, $result);
  645. }
  646. @mysqli_close($connection);
  647. return $result;
  648. }
  649. // }}}
  650. // {{{ _doQuery()
  651. /**
  652. * Execute a query
  653. * @param string $query query
  654. * @param boolean $is_manip if the query is a manipulation query
  655. * @param resource $connection
  656. * @param string $database_name
  657. * @return result or error object
  658. * @access protected
  659. */
  660. function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
  661. {
  662. $this->last_query = $query;
  663. $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
  664. if ($result)
  665. {
  666. if (PEAR :: isError($result))
  667. {
  668. return $result;
  669. }
  670. $query = $result;
  671. }
  672. if ($this->options['disable_query'])
  673. {
  674. $result = $is_manip ? 0 : null;
  675. return $result;
  676. }
  677. if (is_null($connection))
  678. {
  679. $connection = $this->getConnection();
  680. if (PEAR :: isError($connection))
  681. {
  682. return $connection;
  683. }
  684. }
  685. if (is_null($database_name))
  686. {
  687. $database_name = $this->database_name;
  688. }
  689. if ($database_name)
  690. {
  691. if ($database_name != $this->connected_database_name)
  692. {
  693. if (! @mysqli_select_db($connection, $database_name))
  694. {
  695. $err = $this->raiseError(null, null, null, 'Could not select the database: ' . $database_name, __FUNCTION__);
  696. return $err;
  697. }
  698. $this->connected_database_name = $database_name;
  699. }
  700. }
  701. if ($this->options['multi_query'])
  702. {
  703. $result = mysqli_multi_query($connection, $query);
  704. }
  705. else
  706. {
  707. $resultmode = $this->options['result_buffering'] ? MYSQLI_USE_RESULT : MYSQLI_USE_RESULT;
  708. $result = mysqli_query($connection, $query);
  709. }
  710. if (! $result)
  711. {
  712. $err = & $this->raiseError(null, null, null, 'Could not execute statement', __FUNCTION__);
  713. return $err;
  714. }
  715. if ($this->options['multi_query'])
  716. {
  717. if ($this->options['result_buffering'])
  718. {
  719. if (! ($result = @mysqli_store_result($connection)))
  720. {
  721. $err = & $this->raiseError(null, null, null, 'Could not get the first result from a multi query', __FUNCTION__);
  722. return $err;
  723. }
  724. }
  725. elseif (! ($result = @mysqli_use_result($connection)))
  726. {
  727. $err = & $this->raiseError(null, null, null, 'Could not get the first result from a multi query', __FUNCTION__);
  728. return $err;
  729. }
  730. }
  731. $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
  732. return $result;
  733. }
  734. // }}}
  735. // {{{ _affectedRows()
  736. /**
  737. * Returns the number of rows affected
  738. *
  739. * @param resource $result
  740. * @param resource $connection
  741. * @return mixed MDB2 Error Object or the number of rows affected
  742. * @access private
  743. */
  744. function _affectedRows($connection, $result = null)
  745. {
  746. if (is_null($connection))
  747. {
  748. $connection = $this->getConnection();
  749. if (PEAR :: isError($connection))
  750. {
  751. return $connection;
  752. }
  753. }
  754. return @mysqli_affected_rows($connection);
  755. }
  756. // }}}
  757. // {{{ _modifyQuery()
  758. /**
  759. * Changes a query string for various DBMS specific reasons
  760. *
  761. * @param string $query query to modify
  762. * @param boolean $is_manip if it is a DML query
  763. * @param integer $limit limit the number of rows
  764. * @param integer $offset start reading from given offset
  765. * @return string modified query
  766. * @access protected
  767. */
  768. function _modifyQuery($query, $is_manip, $limit, $offset)
  769. {
  770. if ($this->options['portability'] & MDB2_PORTABILITY_DELETE_COUNT)
  771. {
  772. // "DELETE FROM table" gives 0 affected rows in MySQL.
  773. // This little hack lets you know how many rows were deleted.
  774. if (preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $query))
  775. {
  776. $query = preg_replace('/^\s*DELETE\s+FROM\s+(\S+)\s*$/', 'DELETE FROM \1 WHERE 1=1', $query);
  777. }
  778. }
  779. if ($limit > 0 && ! preg_match('/LIMIT\s*\d(?:\s*(?:,|OFFSET)\s*\d+)?(?:[^\)]*)?$/i', $query))
  780. {
  781. $query = rtrim($query);
  782. if (substr($query, - 1) == ';')
  783. {
  784. $query = substr($query, 0, - 1);
  785. }
  786. // LIMIT doesn't always come last in the query
  787. // @see http://dev.mysql.com/doc/refman/5.0/en/select.html
  788. $after = '';
  789. if (preg_match('/(\s+INTO\s+(?:OUT|DUMP)FILE\s.*)$/ims', $query, $matches))
  790. {
  791. $after = $matches[0];
  792. $query = preg_replace('/(\s+INTO\s+(?:OUT|DUMP)FILE\s.*)$/ims', '', $query);
  793. }
  794. elseif (preg_match('/(\s+FOR\s+UPDATE\s*)$/i', $query, $matches))
  795. {
  796. $after = $matches[0];
  797. $query = preg_replace('/(\s+FOR\s+UPDATE\s*)$/im', '', $query);
  798. }
  799. elseif (preg_match('/(\s+LOCK\s+IN\s+SHARE\s+MODE\s*)$/im', $query, $matches))
  800. {
  801. $after = $matches[0];
  802. $query = preg_replace('/(\s+LOCK\s+IN\s+SHARE\s+MODE\s*)$/im', '', $query);
  803. }
  804. if ($is_manip)
  805. {
  806. return $query . " LIMIT $limit" . $after;
  807. }
  808. else
  809. {
  810. return $query . " LIMIT $offset, $limit" . $after;
  811. }
  812. }
  813. return $query;
  814. }
  815. // }}}
  816. // {{{ getServerVersion()
  817. /**
  818. * return version information about the server
  819. *
  820. * @param bool $native determines if the raw version string should be returned
  821. * @return mixed array/string with version information or MDB2 error object
  822. * @access public
  823. */
  824. function getServerVersion($native = false)
  825. {
  826. $connection = $this->getConnection();
  827. if (PEAR :: isError($connection))
  828. {
  829. return $connection;
  830. }
  831. if ($this->connected_server_info)
  832. {
  833. $server_info = $this->connected_server_info;
  834. }
  835. else
  836. {
  837. $server_info = @mysqli_get_server_info($connection);
  838. }
  839. if (! $server_info)
  840. {
  841. return $this->raiseError(null, null, null, 'Could not get server information', __FUNCTION__);
  842. }
  843. // cache server_info
  844. $this->connected_server_info = $server_info;
  845. if (! $native)
  846. {
  847. $tmp = explode('.', $server_info, 3);
  848. if (isset($tmp[2]) && strpos($tmp[2], '-'))
  849. {
  850. $tmp2 = explode('-', @$tmp[2], 2);
  851. }
  852. else
  853. {
  854. $tmp2[0] = isset($tmp[2]) ? $tmp[2] : null;
  855. $tmp2[1] = null;
  856. }
  857. $server_info = array('major' => isset($tmp[0]) ? $tmp[0] : null, 'minor' => isset($tmp[1]) ? $tmp[1] : null,
  858. 'patch' => $tmp2[0], 'extra' => $tmp2[1], 'native' => $server_info);
  859. }
  860. return $server_info;
  861. }
  862. // }}}
  863. // {{{ _getServerCapabilities()
  864. /**
  865. * Fetch some information about the server capabilities
  866. * (transactions, subselects, prepared statements, etc).
  867. *
  868. * @access private
  869. */
  870. function _getServerCapabilities()
  871. {
  872. if (! $this->server_capabilities_checked)
  873. {
  874. $this->server_capabilities_checked = true;
  875. //set defaults
  876. $this->supported['sub_selects'] = 'emulated';
  877. $this->supported['prepared_statements'] = 'emulated';
  878. $this->supported['triggers'] = false;
  879. $this->start_transaction = false;
  880. $this->varchar_max_length = 255;
  881. $server_info = $this->getServerVersion();
  882. if (is_array($server_info))
  883. {
  884. $server_version = $server_info['major'] . '.' . $server_info['minor'] . '.' . $server_info['patch'];
  885. if (! version_compare($server_version, '4.1.0', '<'))
  886. {
  887. $this->supported['sub_selects'] = true;
  888. $this->supported['prepared_statements'] = true;
  889. }
  890. // SAVEPOINTs were introduced in MySQL 4.0.14 and 4.1.1 (InnoDB)
  891. if (version_compare($server_version, '4.1.0', '>='))
  892. {
  893. if (version_compare($server_version, '4.1.1', '<'))
  894. {
  895. $this->supported['savepoints'] = false;
  896. }
  897. }
  898. elseif (version_compare($server_version, '4.0.14', '<'))
  899. {
  900. $this->supported['savepoints'] = false;
  901. }
  902. if (! version_compare($server_version, '4.0.11', '<'))
  903. {
  904. $this->start_transaction = true;
  905. }
  906. if (! version_compare($server_version, '5.0.3', '<'))
  907. {
  908. $this->varchar_max_length = 65532;
  909. }
  910. if (! version_compare($server_version, '5.0.2', '<'))
  911. {
  912. $this->supported['triggers'] = true;
  913. }
  914. }
  915. }
  916. }
  917. // }}}
  918. // {{{ function _skipUserDefinedVariable($query, $position)
  919. /**
  920. * Utility method, used by prepare() to avoid misinterpreting MySQL user
  921. * defined variables (SELECT @x:=5) for placeholders.
  922. * Check if the placeholder is a false positive, i.e. if it is an user defined
  923. * variable instead. If so, skip it and advance the position, otherwise
  924. * return the current position, which is valid
  925. *
  926. * @param string $query
  927. * @param integer $position current string cursor position
  928. * @return integer $new_position
  929. * @access protected
  930. */
  931. function _skipUserDefinedVariable($query, $position)
  932. {
  933. $found = strpos(strrev(substr($query, 0, $position)), '@');
  934. if ($found === false)
  935. {
  936. return $position;
  937. }
  938. $pos = strlen($query) - strlen(substr($query, $position)) - $found - 1;
  939. $substring = substr($query, $pos, $position - $pos + 2);
  940. if (preg_match('/^@\w+\s*:=$/', $substring))
  941. {
  942. return $position + 1; //found an user defined variable: skip it
  943. }
  944. return $position;
  945. }
  946. // }}}
  947. // {{{ prepare()
  948. /**
  949. * Prepares a query for multiple execution with execute().
  950. * With some database backends, this is emulated.
  951. * prepare() requires a generic query as string like
  952. * 'INSERT INTO numbers VALUES(?,?)' or
  953. * 'INSERT INTO numbers VALUES(:foo,:bar)'.
  954. * The ? and :name and are placeholders which can be set using
  955. * bindParam() and the query can be sent off using the execute() method.
  956. * The allowed format for :name can be set with the 'bindname_format' option.
  957. *
  958. * @param string $query the query to prepare
  959. * @param mixed $types array that contains the types of the placeholders
  960. * @param mixed $result_types array that contains the types of the columns in
  961. * the result set or MDB2_PREPARE_RESULT, if set to
  962. * MDB2_PREPARE_MANIP the query is handled as a manipulation query
  963. * @param mixed $lobs key (field) value (parameter) pair for all lob placeholders
  964. * @return mixed resource handle for the prepared query on success, a MDB2
  965. * error on failure
  966. * @access public
  967. * @see bindParam, execute
  968. */
  969. function &prepare($query, $types = null, $result_types = null, $lobs = array())
  970. {
  971. if ($this->options['emulate_prepared'] || $this->supported['prepared_statements'] !== true)
  972. {
  973. $obj = & parent :: prepare($query, $types, $result_types, $lobs);
  974. return $obj;
  975. }
  976. $is_manip = ($result_types === MDB2_PREPARE_MANIP);
  977. $offset = $this->offset;
  978. $limit = $this->limit;
  979. $this->offset = $this->limit = 0;
  980. $query = $this->_modifyQuery($query, $is_manip, $limit, $offset);
  981. $result = $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'pre'));
  982. if ($result)
  983. {
  984. if (PEAR :: isError($result))
  985. {
  986. return $result;
  987. }
  988. $query = $result;
  989. }
  990. $placeholder_type_guess = $placeholder_type = null;
  991. $question = '?';
  992. $colon = ':';
  993. $positions = array();
  994. $position = 0;
  995. while ($position < strlen($query))
  996. {
  997. $q_position = strpos($query, $question, $position);
  998. $c_position = strpos($query, $colon, $position);
  999. if ($q_position && $c_position)
  1000. {
  1001. $p_position = min($q_position, $c_position);
  1002. }
  1003. elseif ($q_position)
  1004. {
  1005. $p_position = $q_position;
  1006. }
  1007. elseif ($c_position)
  1008. {
  1009. $p_position = $c_position;
  1010. }
  1011. else
  1012. {
  1013. break;
  1014. }
  1015. if (is_null($placeholder_type))
  1016. {
  1017. $placeholder_type_guess = $query[$p_position];
  1018. }
  1019. $new_pos = $this->_skipDelimitedStrings($query, $position, $p_position);
  1020. if (PEAR :: isError($new_pos))
  1021. {
  1022. return $new_pos;
  1023. }
  1024. if ($new_pos != $position)
  1025. {
  1026. $position = $new_pos;
  1027. continue; //evaluate again starting from the new position
  1028. }
  1029. //make sure this is not part of an user defined variable
  1030. $new_pos = $this->_skipUserDefinedVariable($query, $position);
  1031. if ($new_pos != $position)
  1032. {
  1033. $position = $new_pos;
  1034. continue; //evaluate again starting from the new position
  1035. }
  1036. if ($query[$position] == $placeholder_type_guess)
  1037. {
  1038. if (is_null($placeholder_type))
  1039. {
  1040. $placeholder_type = $query[$p_position];
  1041. $question = $colon = $placeholder_type;
  1042. }
  1043. if ($placeholder_type == ':')
  1044. {
  1045. $regexp = '/^.{' . ($position + 1) . '}(' . $this->options['bindname_format'] . ').*$/s';
  1046. $parameter = preg_replace($regexp, '\\1', $query);
  1047. if ($parameter === '')
  1048. {
  1049. $err = & $this->raiseError(MDB2_ERROR_SYNTAX, null, null, 'named parameter name must match "bindname_format" option', __FUNCTION__);
  1050. return $err;
  1051. }
  1052. $positions[$p_position] = $parameter;
  1053. $query = substr_replace($query, '?', $position, strlen($parameter) + 1);
  1054. }
  1055. else
  1056. {
  1057. $positions[$p_position] = count($positions);
  1058. }
  1059. $position = $p_position + 1;
  1060. }
  1061. else
  1062. {
  1063. $position = $p_position;
  1064. }
  1065. }
  1066. $connection = $this->getConnection();
  1067. if (PEAR :: isError($connection))
  1068. {
  1069. return $connection;
  1070. }
  1071. if (! $is_manip)
  1072. {
  1073. static $prep_statement_counter = 1;
  1074. $statement_name = sprintf($this->options['statement_format'], $this->phptype, $prep_statement_counter ++ . sha1(microtime() + mt_rand()));
  1075. $statement_name = substr(strtolower($statement_name), 0, $this->options['max_identifiers_length']);
  1076. $query = "PREPARE $statement_name FROM " . $this->quote($query, 'text');
  1077. $statement = & $this->_doQuery($query, true, $connection);
  1078. if (PEAR :: isError($statement))
  1079. {
  1080. return $statement;
  1081. }
  1082. $statement = $statement_name;
  1083. }
  1084. else
  1085. {
  1086. $statement = @mysqli_prepare($connection, $query);
  1087. if (! $statement)
  1088. {
  1089. $err = & $this->raiseError(null, null, null, 'Unable to create prepared statement handle', __FUNCTION__);
  1090. return $err;
  1091. }
  1092. }
  1093. $class_name = 'MDB2_Statement_' . $this->phptype;
  1094. $obj = new $class_name($this, $statement, $positions, $query, $types, $result_types, $is_manip, $limit, $offset);
  1095. $this->debug($query, __FUNCTION__, array('is_manip' => $is_manip, 'when' => 'post', 'result' => $obj));
  1096. return $obj;
  1097. }
  1098. // }}}
  1099. // {{{ replace()
  1100. /**
  1101. * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
  1102. * query, except that if there is already a row in the table with the same
  1103. * key field values, the old row is deleted before the new row is inserted.
  1104. *
  1105. * The REPLACE type of query does not make part of the SQL standards. Since
  1106. * practically only MySQL implements it natively, this type of query is
  1107. * emulated through this method for other DBMS using standard types of
  1108. * queries inside a transaction to assure the atomicity of the operation.
  1109. *
  1110. * @access public
  1111. *
  1112. * @param string $table name of the table on which the REPLACE query will
  1113. * be executed.
  1114. * @param array $fields associative array that describes the fields and the
  1115. * values that will be inserted or updated in the specified table. The
  1116. * indexes of the array are the names of all the fields of the table. The
  1117. * values of the array are also associative arrays that describe the
  1118. * values and other properties of the table fields.
  1119. *
  1120. * Here follows a list of field properties that need to be specified:
  1121. *
  1122. * value:
  1123. * Value to be assigned to the specified field. This value may be
  1124. * of specified in database independent type format as this
  1125. * function can perform the necessary datatype conversions.
  1126. *
  1127. * Default:
  1128. * this property is required unless the Null property
  1129. * is set to 1.
  1130. *
  1131. * type
  1132. * Name of the type of the field. Currently, all types Metabase
  1133. * are supported except for clob and blob.
  1134. *
  1135. * Default: no type conversion
  1136. *
  1137. * null
  1138. * Boolean property that indicates that the value for this field
  1139. * should be set to null.
  1140. *
  1141. * The default value for fields missing in INSERT queries may be
  1142. * specified the definition of a table. Often, the default value
  1143. * is already null, but since the REPLACE may be emulated using
  1144. * an UPDATE query, make sure that all fields of the table are
  1145. * listed in this function argument array.
  1146. *
  1147. * Default: 0
  1148. *
  1149. * key
  1150. * Boolean property that indicates that this field should be
  1151. * handled as a primary key or at least as part of the compound
  1152. * unique index of the table that will determine the row that will
  1153. * updated if it exists or inserted a new row otherwise.
  1154. *
  1155. * This function will fail if no key field is specified or if the
  1156. * value of a key field is set to null because fields that are
  1157. * part of unique index they may not be null.
  1158. *
  1159. * Default: 0
  1160. *
  1161. * @see http://dev.mysql.com/doc/refman/5.0/en/replace.html
  1162. * @return mixed MDB2_OK on success, a MDB2 error on failure
  1163. */
  1164. function replace($table, $fields)
  1165. {
  1166. $count = count($fields);
  1167. $query = $values = '';
  1168. $keys = $colnum = 0;
  1169. for(reset($fields); $colnum < $count; next($fields), $colnum ++)
  1170. {
  1171. $name = key($fields);
  1172. if ($colnum > 0)
  1173. {
  1174. $query .= ',';
  1175. $values .= ',';
  1176. }
  1177. $query .= $this->quoteIdentifier($name, true);
  1178. if (isset($fields[$name]['null']) && $fields[$name]['null'])
  1179. {
  1180. $value = 'NULL';
  1181. }
  1182. else
  1183. {
  1184. $type = isset($fields[$name]['type']) ? $fields[$name]['type'] : null;
  1185. $value = $this->quote($fields[$name]['value'], $type);
  1186. if (PEAR :: isError($value))
  1187. {
  1188. return $value;
  1189. }
  1190. }
  1191. $values .= $value;
  1192. if (isset($fields[$name]['key']) && $fields[$name]['key'])
  1193. {
  1194. if ($value === 'NULL')
  1195. {
  1196. return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null, 'key value ' . $name . ' may not be NULL', __FUNCTION__);
  1197. }
  1198. $keys ++;
  1199. }
  1200. }
  1201. if ($keys == 0)
  1202. {
  1203. return $this->raiseError(MDB2_ERROR_CANNOT_REPLACE, null, null, 'not specified which fields are keys', __FUNCTION__);
  1204. }
  1205. $connection = $this->getConnection();

Large files files are truncated, but you can click here to view the full file