Mysql.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. <?php
  2. /**
  3. * MySQL layer for DBO
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Model.Datasource.Database
  16. * @since CakePHP(tm) v 0.10.5.1790
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('DboSource', 'Model/Datasource');
  20. /**
  21. * MySQL DBO driver object
  22. *
  23. * Provides connection and SQL generation for MySQL RDMS
  24. *
  25. * @package Cake.Model.Datasource.Database
  26. */
  27. class Mysql extends DboSource {
  28. /**
  29. * Datasource description
  30. *
  31. * @var string
  32. */
  33. public $description = "MySQL DBO Driver";
  34. /**
  35. * Base configuration settings for MySQL driver
  36. *
  37. * @var array
  38. */
  39. protected $_baseConfig = array(
  40. 'persistent' => true,
  41. 'host' => 'localhost',
  42. 'login' => 'root',
  43. 'password' => '',
  44. 'database' => 'cake',
  45. 'port' => '3306'
  46. );
  47. /**
  48. * Reference to the PDO object connection
  49. *
  50. * @var PDO $_connection
  51. */
  52. protected $_connection = null;
  53. /**
  54. * Start quote
  55. *
  56. * @var string
  57. */
  58. public $startQuote = "`";
  59. /**
  60. * End quote
  61. *
  62. * @var string
  63. */
  64. public $endQuote = "`";
  65. /**
  66. * use alias for update and delete. Set to true if version >= 4.1
  67. *
  68. * @var boolean
  69. */
  70. protected $_useAlias = true;
  71. /**
  72. * List of engine specific additional field parameters used on table creating
  73. *
  74. * @var array
  75. */
  76. public $fieldParameters = array(
  77. 'charset' => array('value' => 'CHARACTER SET', 'quote' => false, 'join' => ' ', 'column' => false, 'position' => 'beforeDefault'),
  78. 'collate' => array('value' => 'COLLATE', 'quote' => false, 'join' => ' ', 'column' => 'Collation', 'position' => 'beforeDefault'),
  79. 'comment' => array('value' => 'COMMENT', 'quote' => true, 'join' => ' ', 'column' => 'Comment', 'position' => 'afterDefault')
  80. );
  81. /**
  82. * List of table engine specific parameters used on table creating
  83. *
  84. * @var array
  85. */
  86. public $tableParameters = array(
  87. 'charset' => array('value' => 'DEFAULT CHARSET', 'quote' => false, 'join' => '=', 'column' => 'charset'),
  88. 'collate' => array('value' => 'COLLATE', 'quote' => false, 'join' => '=', 'column' => 'Collation'),
  89. 'engine' => array('value' => 'ENGINE', 'quote' => false, 'join' => '=', 'column' => 'Engine')
  90. );
  91. /**
  92. * MySQL column definition
  93. *
  94. * @var array
  95. */
  96. public $columns = array(
  97. 'primary_key' => array('name' => 'NOT NULL AUTO_INCREMENT'),
  98. 'string' => array('name' => 'varchar', 'limit' => '255'),
  99. 'text' => array('name' => 'text'),
  100. 'biginteger' => array('name' => 'bigint', 'limit' => '20'),
  101. 'integer' => array('name' => 'int', 'limit' => '11', 'formatter' => 'intval'),
  102. 'float' => array('name' => 'float', 'formatter' => 'floatval'),
  103. 'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
  104. 'timestamp' => array('name' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'formatter' => 'date'),
  105. 'time' => array('name' => 'time', 'format' => 'H:i:s', 'formatter' => 'date'),
  106. 'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
  107. 'binary' => array('name' => 'blob'),
  108. 'boolean' => array('name' => 'tinyint', 'limit' => '1')
  109. );
  110. /**
  111. * Connects to the database using options in the given configuration array.
  112. *
  113. * @return boolean True if the database could be connected, else false
  114. * @throws MissingConnectionException
  115. */
  116. public function connect() {
  117. $config = $this->config;
  118. $this->connected = false;
  119. try {
  120. $flags = array(
  121. PDO::ATTR_PERSISTENT => $config['persistent'],
  122. PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
  123. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  124. );
  125. if (!empty($config['encoding'])) {
  126. $flags[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $config['encoding'];
  127. }
  128. if (empty($config['unix_socket'])) {
  129. $dsn = "mysql:host={$config['host']};port={$config['port']};dbname={$config['database']}";
  130. } else {
  131. $dsn = "mysql:unix_socket={$config['unix_socket']};dbname={$config['database']}";
  132. }
  133. $this->_connection = new PDO(
  134. $dsn,
  135. $config['login'],
  136. $config['password'],
  137. $flags
  138. );
  139. $this->connected = true;
  140. } catch (PDOException $e) {
  141. throw new MissingConnectionException(array('class' => $e->getMessage()));
  142. }
  143. $this->_useAlias = (bool)version_compare($this->getVersion(), "4.1", ">=");
  144. return $this->connected;
  145. }
  146. /**
  147. * Check whether the MySQL extension is installed/loaded
  148. *
  149. * @return boolean
  150. */
  151. public function enabled() {
  152. return in_array('mysql', PDO::getAvailableDrivers());
  153. }
  154. /**
  155. * Returns an array of sources (tables) in the database.
  156. *
  157. * @param mixed $data
  158. * @return array Array of table names in the database
  159. */
  160. public function listSources($data = null) {
  161. $cache = parent::listSources();
  162. if ($cache != null) {
  163. return $cache;
  164. }
  165. $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']));
  166. if (!$result) {
  167. $result->closeCursor();
  168. return array();
  169. } else {
  170. $tables = array();
  171. while ($line = $result->fetch(PDO::FETCH_NUM)) {
  172. $tables[] = $line[0];
  173. }
  174. $result->closeCursor();
  175. parent::listSources($tables);
  176. return $tables;
  177. }
  178. }
  179. /**
  180. * Builds a map of the columns contained in a result
  181. *
  182. * @param PDOStatement $results
  183. * @return void
  184. */
  185. public function resultSet($results) {
  186. $this->map = array();
  187. $numFields = $results->columnCount();
  188. $index = 0;
  189. while ($numFields-- > 0) {
  190. $column = $results->getColumnMeta($index);
  191. if (empty($column['native_type'])) {
  192. $type = ($column['len'] == 1) ? 'boolean' : 'string';
  193. } else {
  194. $type = $column['native_type'];
  195. }
  196. if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) {
  197. $this->map[$index++] = array($column['table'], $column['name'], $type);
  198. } else {
  199. $this->map[$index++] = array(0, $column['name'], $type);
  200. }
  201. }
  202. }
  203. /**
  204. * Fetches the next row from the current result set
  205. *
  206. * @return mixed array with results fetched and mapped to column names or false if there is no results left to fetch
  207. */
  208. public function fetchResult() {
  209. if ($row = $this->_result->fetch(PDO::FETCH_NUM)) {
  210. $resultRow = array();
  211. foreach ($this->map as $col => $meta) {
  212. list($table, $column, $type) = $meta;
  213. $resultRow[$table][$column] = $row[$col];
  214. if ($type === 'boolean' && $row[$col] !== null) {
  215. $resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
  216. }
  217. }
  218. return $resultRow;
  219. }
  220. $this->_result->closeCursor();
  221. return false;
  222. }
  223. /**
  224. * Gets the database encoding
  225. *
  226. * @return string The database encoding
  227. */
  228. public function getEncoding() {
  229. return $this->_execute('SHOW VARIABLES LIKE ?', array('character_set_client'))->fetchObject()->Value;
  230. }
  231. /**
  232. * Query charset by collation
  233. *
  234. * @param string $name Collation name
  235. * @return string Character set name
  236. */
  237. public function getCharsetName($name) {
  238. if ((bool)version_compare($this->getVersion(), "5", ">=")) {
  239. $r = $this->_execute('SELECT CHARACTER_SET_NAME FROM INFORMATION_SCHEMA.COLLATIONS WHERE COLLATION_NAME = ?', array($name));
  240. $cols = $r->fetch(PDO::FETCH_ASSOC);
  241. if (isset($cols['CHARACTER_SET_NAME'])) {
  242. return $cols['CHARACTER_SET_NAME'];
  243. }
  244. }
  245. return false;
  246. }
  247. /**
  248. * Returns an array of the fields in given table name.
  249. *
  250. * @param Model|string $model Name of database table to inspect or model instance
  251. * @return array Fields in table. Keys are name and type
  252. * @throws CakeException
  253. */
  254. public function describe($model) {
  255. $key = $this->fullTableName($model, false);
  256. $cache = parent::describe($key);
  257. if ($cache != null) {
  258. return $cache;
  259. }
  260. $table = $this->fullTableName($model);
  261. $fields = false;
  262. $cols = $this->_execute('SHOW FULL COLUMNS FROM ' . $table);
  263. if (!$cols) {
  264. throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $table));
  265. }
  266. while ($column = $cols->fetch(PDO::FETCH_OBJ)) {
  267. $fields[$column->Field] = array(
  268. 'type' => $this->column($column->Type),
  269. 'null' => ($column->Null === 'YES' ? true : false),
  270. 'default' => $column->Default,
  271. 'length' => $this->length($column->Type),
  272. );
  273. if (!empty($column->Key) && isset($this->index[$column->Key])) {
  274. $fields[$column->Field]['key'] = $this->index[$column->Key];
  275. }
  276. foreach ($this->fieldParameters as $name => $value) {
  277. if (!empty($column->{$value['column']})) {
  278. $fields[$column->Field][$name] = $column->{$value['column']};
  279. }
  280. }
  281. if (isset($fields[$column->Field]['collate'])) {
  282. $charset = $this->getCharsetName($fields[$column->Field]['collate']);
  283. if ($charset) {
  284. $fields[$column->Field]['charset'] = $charset;
  285. }
  286. }
  287. }
  288. $this->_cacheDescription($key, $fields);
  289. $cols->closeCursor();
  290. return $fields;
  291. }
  292. /**
  293. * Generates and executes an SQL UPDATE statement for given model, fields, and values.
  294. *
  295. * @param Model $model
  296. * @param array $fields
  297. * @param array $values
  298. * @param mixed $conditions
  299. * @return array
  300. */
  301. public function update(Model $model, $fields = array(), $values = null, $conditions = null) {
  302. if (!$this->_useAlias) {
  303. return parent::update($model, $fields, $values, $conditions);
  304. }
  305. if ($values == null) {
  306. $combined = $fields;
  307. } else {
  308. $combined = array_combine($fields, $values);
  309. }
  310. $alias = $joins = false;
  311. $fields = $this->_prepareUpdateFields($model, $combined, empty($conditions), !empty($conditions));
  312. $fields = implode(', ', $fields);
  313. $table = $this->fullTableName($model);
  314. if (!empty($conditions)) {
  315. $alias = $this->name($model->alias);
  316. if ($model->name == $model->alias) {
  317. $joins = implode(' ', $this->_getJoins($model));
  318. }
  319. }
  320. $conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), true, true, $model);
  321. if ($conditions === false) {
  322. return false;
  323. }
  324. if (!$this->execute($this->renderStatement('update', compact('table', 'alias', 'joins', 'fields', 'conditions')))) {
  325. $model->onError();
  326. return false;
  327. }
  328. return true;
  329. }
  330. /**
  331. * Generates and executes an SQL DELETE statement for given id/conditions on given model.
  332. *
  333. * @param Model $model
  334. * @param mixed $conditions
  335. * @return boolean Success
  336. */
  337. public function delete(Model $model, $conditions = null) {
  338. if (!$this->_useAlias) {
  339. return parent::delete($model, $conditions);
  340. }
  341. $alias = $this->name($model->alias);
  342. $table = $this->fullTableName($model);
  343. $joins = implode(' ', $this->_getJoins($model));
  344. if (empty($conditions)) {
  345. $alias = $joins = false;
  346. }
  347. $complexConditions = false;
  348. foreach ((array)$conditions as $key => $value) {
  349. if (strpos($key, $model->alias) === false) {
  350. $complexConditions = true;
  351. break;
  352. }
  353. }
  354. if (!$complexConditions) {
  355. $joins = false;
  356. }
  357. $conditions = $this->conditions($this->defaultConditions($model, $conditions, $alias), true, true, $model);
  358. if ($conditions === false) {
  359. return false;
  360. }
  361. if ($this->execute($this->renderStatement('delete', compact('alias', 'table', 'joins', 'conditions'))) === false) {
  362. $model->onError();
  363. return false;
  364. }
  365. return true;
  366. }
  367. /**
  368. * Sets the database encoding
  369. *
  370. * @param string $enc Database encoding
  371. * @return boolean
  372. */
  373. public function setEncoding($enc) {
  374. return $this->_execute('SET NAMES ' . $enc) !== false;
  375. }
  376. /**
  377. * Returns an array of the indexes in given datasource name.
  378. *
  379. * @param string $model Name of model to inspect
  380. * @return array Fields in table. Keys are column and unique
  381. */
  382. public function index($model) {
  383. $index = array();
  384. $table = $this->fullTableName($model);
  385. $old = version_compare($this->getVersion(), '4.1', '<=');
  386. if ($table) {
  387. $indices = $this->_execute('SHOW INDEX FROM ' . $table);
  388. // @codingStandardsIgnoreStart
  389. // MySQL columns don't match the cakephp conventions.
  390. while ($idx = $indices->fetch(PDO::FETCH_OBJ)) {
  391. if ($old) {
  392. $idx = (object)current((array)$idx);
  393. }
  394. if (!isset($index[$idx->Key_name]['column'])) {
  395. $col = array();
  396. $index[$idx->Key_name]['column'] = $idx->Column_name;
  397. $index[$idx->Key_name]['unique'] = intval($idx->Non_unique == 0);
  398. } else {
  399. if (!empty($index[$idx->Key_name]['column']) && !is_array($index[$idx->Key_name]['column'])) {
  400. $col[] = $index[$idx->Key_name]['column'];
  401. }
  402. $col[] = $idx->Column_name;
  403. $index[$idx->Key_name]['column'] = $col;
  404. }
  405. }
  406. // @codingStandardsIgnoreEnd
  407. $indices->closeCursor();
  408. }
  409. return $index;
  410. }
  411. /**
  412. * Generate a MySQL Alter Table syntax for the given Schema comparison
  413. *
  414. * @param array $compare Result of a CakeSchema::compare()
  415. * @param string $table
  416. * @return array Array of alter statements to make.
  417. */
  418. public function alterSchema($compare, $table = null) {
  419. if (!is_array($compare)) {
  420. return false;
  421. }
  422. $out = '';
  423. $colList = array();
  424. foreach ($compare as $curTable => $types) {
  425. $indexes = $tableParameters = $colList = array();
  426. if (!$table || $table == $curTable) {
  427. $out .= 'ALTER TABLE ' . $this->fullTableName($curTable) . " \n";
  428. foreach ($types as $type => $column) {
  429. if (isset($column['indexes'])) {
  430. $indexes[$type] = $column['indexes'];
  431. unset($column['indexes']);
  432. }
  433. if (isset($column['tableParameters'])) {
  434. $tableParameters[$type] = $column['tableParameters'];
  435. unset($column['tableParameters']);
  436. }
  437. switch ($type) {
  438. case 'add':
  439. foreach ($column as $field => $col) {
  440. $col['name'] = $field;
  441. $alter = 'ADD ' . $this->buildColumn($col);
  442. if (isset($col['after'])) {
  443. $alter .= ' AFTER ' . $this->name($col['after']);
  444. }
  445. $colList[] = $alter;
  446. }
  447. break;
  448. case 'drop':
  449. foreach ($column as $field => $col) {
  450. $col['name'] = $field;
  451. $colList[] = 'DROP ' . $this->name($field);
  452. }
  453. break;
  454. case 'change':
  455. foreach ($column as $field => $col) {
  456. if (!isset($col['name'])) {
  457. $col['name'] = $field;
  458. }
  459. $colList[] = 'CHANGE ' . $this->name($field) . ' ' . $this->buildColumn($col);
  460. }
  461. break;
  462. }
  463. }
  464. $colList = array_merge($colList, $this->_alterIndexes($curTable, $indexes));
  465. $colList = array_merge($colList, $this->_alterTableParameters($curTable, $tableParameters));
  466. $out .= "\t" . implode(",\n\t", $colList) . ";\n\n";
  467. }
  468. }
  469. return $out;
  470. }
  471. /**
  472. * Generate a MySQL "drop table" statement for the given Schema object
  473. *
  474. * @param CakeSchema $schema An instance of a subclass of CakeSchema
  475. * @param string $table Optional. If specified only the table name given will be generated.
  476. * Otherwise, all tables defined in the schema are generated.
  477. * @return string
  478. */
  479. public function dropSchema(CakeSchema $schema, $table = null) {
  480. $out = '';
  481. foreach ($schema->tables as $curTable => $columns) {
  482. if (!$table || $table === $curTable) {
  483. $out .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n";
  484. }
  485. }
  486. return $out;
  487. }
  488. /**
  489. * Generate MySQL table parameter alteration statements for a table.
  490. *
  491. * @param string $table Table to alter parameters for.
  492. * @param array $parameters Parameters to add & drop.
  493. * @return array Array of table property alteration statements.
  494. */
  495. protected function _alterTableParameters($table, $parameters) {
  496. if (isset($parameters['change'])) {
  497. return $this->buildTableParameters($parameters['change']);
  498. }
  499. return array();
  500. }
  501. /**
  502. * Generate MySQL index alteration statements for a table.
  503. *
  504. * @param string $table Table to alter indexes for
  505. * @param array $indexes Indexes to add and drop
  506. * @return array Index alteration statements
  507. */
  508. protected function _alterIndexes($table, $indexes) {
  509. $alter = array();
  510. if (isset($indexes['drop'])) {
  511. foreach ($indexes['drop'] as $name => $value) {
  512. $out = 'DROP ';
  513. if ($name == 'PRIMARY') {
  514. $out .= 'PRIMARY KEY';
  515. } else {
  516. $out .= 'KEY ' . $name;
  517. }
  518. $alter[] = $out;
  519. }
  520. }
  521. if (isset($indexes['add'])) {
  522. foreach ($indexes['add'] as $name => $value) {
  523. $out = 'ADD ';
  524. if ($name == 'PRIMARY') {
  525. $out .= 'PRIMARY ';
  526. $name = null;
  527. } else {
  528. if (!empty($value['unique'])) {
  529. $out .= 'UNIQUE ';
  530. }
  531. }
  532. if (is_array($value['column'])) {
  533. $out .= 'KEY ' . $name . ' (' . implode(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
  534. } else {
  535. $out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')';
  536. }
  537. $alter[] = $out;
  538. }
  539. }
  540. return $alter;
  541. }
  542. /**
  543. * Returns an detailed array of sources (tables) in the database.
  544. *
  545. * @param string $name Table name to get parameters
  546. * @return array Array of table names in the database
  547. */
  548. public function listDetailedSources($name = null) {
  549. $condition = '';
  550. if (is_string($name)) {
  551. $condition = ' WHERE name = ' . $this->value($name);
  552. }
  553. $result = $this->_connection->query('SHOW TABLE STATUS ' . $condition, PDO::FETCH_ASSOC);
  554. if (!$result) {
  555. $result->closeCursor();
  556. return array();
  557. } else {
  558. $tables = array();
  559. foreach ($result as $row) {
  560. $tables[$row['Name']] = (array)$row;
  561. unset($tables[$row['Name']]['queryString']);
  562. if (!empty($row['Collation'])) {
  563. $charset = $this->getCharsetName($row['Collation']);
  564. if ($charset) {
  565. $tables[$row['Name']]['charset'] = $charset;
  566. }
  567. }
  568. }
  569. $result->closeCursor();
  570. if (is_string($name) && isset($tables[$name])) {
  571. return $tables[$name];
  572. }
  573. return $tables;
  574. }
  575. }
  576. /**
  577. * Converts database-layer column types to basic types
  578. *
  579. * @param string $real Real database-layer column type (i.e. "varchar(255)")
  580. * @return string Abstract column type (i.e. "string")
  581. */
  582. public function column($real) {
  583. if (is_array($real)) {
  584. $col = $real['name'];
  585. if (isset($real['limit'])) {
  586. $col .= '(' . $real['limit'] . ')';
  587. }
  588. return $col;
  589. }
  590. $col = str_replace(')', '', $real);
  591. $limit = $this->length($real);
  592. if (strpos($col, '(') !== false) {
  593. list($col, $vals) = explode('(', $col);
  594. }
  595. if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
  596. return $col;
  597. }
  598. if (($col === 'tinyint' && $limit == 1) || $col === 'boolean') {
  599. return 'boolean';
  600. }
  601. if (strpos($col, 'bigint') !== false || $col === 'bigint') {
  602. return 'biginteger';
  603. }
  604. if (strpos($col, 'int') !== false) {
  605. return 'integer';
  606. }
  607. if (strpos($col, 'char') !== false || $col === 'tinytext') {
  608. return 'string';
  609. }
  610. if (strpos($col, 'text') !== false) {
  611. return 'text';
  612. }
  613. if (strpos($col, 'blob') !== false || $col === 'binary') {
  614. return 'binary';
  615. }
  616. if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {
  617. return 'float';
  618. }
  619. if (strpos($col, 'enum') !== false) {
  620. return "enum($vals)";
  621. }
  622. return 'text';
  623. }
  624. /**
  625. * Gets the schema name
  626. *
  627. * @return string The schema name
  628. */
  629. public function getSchemaName() {
  630. return $this->config['database'];
  631. }
  632. /**
  633. * Check if the server support nested transactions
  634. *
  635. * @return boolean
  636. */
  637. public function nestedTransactionSupported() {
  638. return $this->useNestedTransactions && version_compare($this->getVersion(), '4.1', '>=');
  639. }
  640. }