PropelPDO.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. /**
  10. * PDO connection subclass that provides the basic fixes to PDO that are required by Propel.
  11. *
  12. * This class was designed to work around the limitation in PDO where attempting to begin
  13. * a transaction when one has already been begun will trigger a PDOException. Propel
  14. * relies on the ability to create nested transactions, even if the underlying layer
  15. * simply ignores these (because it doesn't support nested transactions).
  16. *
  17. * The changes that this class makes to the underlying API include the addition of the
  18. * getNestedTransactionDepth() and isInTransaction() and the fact that beginTransaction()
  19. * will no longer throw a PDOException (or trigger an error) if a transaction is already
  20. * in-progress.
  21. *
  22. * @author Cameron Brunner <cameron.brunner@gmail.com>
  23. * @author Hans Lellelid <hans@xmpl.org>
  24. * @author Christian Abegg <abegg.ch@gmail.com>
  25. * @since 2006-09-22
  26. * @package propel.runtime.connection
  27. */
  28. class PropelPDO extends PDO
  29. {
  30. /**
  31. * Attribute to use to set whether to cache prepared statements.
  32. */
  33. const PROPEL_ATTR_CACHE_PREPARES = -1;
  34. const DEFAULT_SLOW_THRESHOLD = 0.1;
  35. const DEFAULT_ONLYSLOW_ENABLED = false;
  36. /**
  37. * The current transaction depth.
  38. * @var int
  39. */
  40. protected $nestedTransactionCount = 0;
  41. /**
  42. * Cache of prepared statements (PDOStatement) keyed by md5 of SQL.
  43. *
  44. * @var array [md5(sql) => PDOStatement]
  45. */
  46. protected $preparedStatements = array();
  47. /**
  48. * Whether to cache prepared statements.
  49. *
  50. * @var boolean
  51. */
  52. protected $cachePreparedStatements = false;
  53. /**
  54. * Whether the final commit is possible
  55. * Is false if a nested transaction is rolled back
  56. */
  57. protected $isUncommitable = false;
  58. /**
  59. * Count of queries performed.
  60. *
  61. * @var int
  62. */
  63. protected $queryCount = 0;
  64. /**
  65. * SQL code of the latest performed query.
  66. *
  67. * @var string
  68. */
  69. protected $lastExecutedQuery;
  70. /**
  71. * Whether or not the debug is enabled
  72. *
  73. * @var boolean
  74. */
  75. public $useDebug = false;
  76. /**
  77. * Configured BasicLogger (or compatible) logger.
  78. *
  79. * @var BasicLogger
  80. */
  81. protected $logger;
  82. /**
  83. * The log level to use for logging.
  84. *
  85. * @var int
  86. */
  87. private $logLevel = Propel::LOG_DEBUG;
  88. /**
  89. * The default value for runtime config item "debugpdo.logging.methods".
  90. *
  91. * @var array
  92. */
  93. protected static $defaultLogMethods = array(
  94. 'PropelPDO::exec',
  95. 'PropelPDO::query',
  96. 'DebugPDOStatement::execute',
  97. );
  98. /**
  99. * Creates a PropelPDO instance representing a connection to a database.
  100. *.
  101. * If so configured, specifies a custom PDOStatement class and makes an entry
  102. * to the log with the state of this object just after its initialization.
  103. * Add PropelPDO::__construct to $defaultLogMethods to see this message
  104. *
  105. * @param string $dsn Connection DSN.
  106. * @param string $username (optional) The user name for the DSN string.
  107. * @param string $password (optional) The password for the DSN string.
  108. * @param array $driver_options (optional) A key=>value array of driver-specific connection options.
  109. * @throws PDOException if there is an error during connection initialization.
  110. */
  111. public function __construct($dsn, $username = null, $password = null, $driver_options = array())
  112. {
  113. if ($this->useDebug) {
  114. $debug = $this->getDebugSnapshot();
  115. }
  116. parent::__construct($dsn, $username, $password, $driver_options);
  117. if ($this->useDebug) {
  118. $this->configureStatementClass('DebugPDOStatement', $suppress = true);
  119. $this->log('Opening connection', null, __METHOD__, $debug);
  120. }
  121. }
  122. /**
  123. * Gets the current transaction depth.
  124. * @return int
  125. */
  126. public function getNestedTransactionCount()
  127. {
  128. return $this->nestedTransactionCount;
  129. }
  130. /**
  131. * Set the current transaction depth.
  132. * @param int $v The new depth.
  133. */
  134. protected function setNestedTransactionCount($v)
  135. {
  136. $this->nestedTransactionCount = $v;
  137. }
  138. /**
  139. * Is this PDO connection currently in-transaction?
  140. * This is equivalent to asking whether the current nested transaction count
  141. * is greater than 0.
  142. * @return boolean
  143. */
  144. public function isInTransaction()
  145. {
  146. return ($this->getNestedTransactionCount() > 0);
  147. }
  148. /**
  149. * Check whether the connection contains a transaction that can be committed.
  150. * To be used in an evironment where Propelexceptions are caught.
  151. *
  152. * @return boolean True if the connection is in a committable transaction
  153. */
  154. public function isCommitable()
  155. {
  156. return $this->isInTransaction() && !$this->isUncommitable;
  157. }
  158. /**
  159. * Overrides PDO::beginTransaction() to prevent errors due to already-in-progress transaction.
  160. */
  161. public function beginTransaction()
  162. {
  163. $return = true;
  164. if (!$this->nestedTransactionCount) {
  165. $return = parent::beginTransaction();
  166. if ($this->useDebug) {
  167. $this->log('Begin transaction', null, __METHOD__);
  168. }
  169. $this->isUncommitable = false;
  170. }
  171. $this->nestedTransactionCount++;
  172. return $return;
  173. }
  174. /**
  175. * Overrides PDO::commit() to only commit the transaction if we are in the outermost
  176. * transaction nesting level.
  177. */
  178. public function commit()
  179. {
  180. $return = true;
  181. $opcount = $this->nestedTransactionCount;
  182. if ($opcount > 0) {
  183. if ($opcount === 1) {
  184. if ($this->isUncommitable) {
  185. throw new PropelException('Cannot commit because a nested transaction was rolled back');
  186. } else {
  187. $return = parent::commit();
  188. if ($this->useDebug) {
  189. $this->log('Commit transaction', null, __METHOD__);
  190. }
  191. }
  192. }
  193. $this->nestedTransactionCount--;
  194. }
  195. return $return;
  196. }
  197. /**
  198. * Overrides PDO::rollBack() to only rollback the transaction if we are in the outermost
  199. * transaction nesting level
  200. * @return boolean Whether operation was successful.
  201. */
  202. public function rollBack()
  203. {
  204. $return = true;
  205. $opcount = $this->nestedTransactionCount;
  206. if ($opcount > 0) {
  207. if ($opcount === 1) {
  208. $return = parent::rollBack();
  209. if ($this->useDebug) {
  210. $this->log('Rollback transaction', null, __METHOD__);
  211. }
  212. } else {
  213. $this->isUncommitable = true;
  214. }
  215. $this->nestedTransactionCount--;
  216. }
  217. return $return;
  218. }
  219. /**
  220. * Rollback the whole transaction, even if this is a nested rollback
  221. * and reset the nested transaction count to 0.
  222. * @return boolean Whether operation was successful.
  223. */
  224. public function forceRollBack()
  225. {
  226. $return = true;
  227. if ($this->nestedTransactionCount) {
  228. // If we're in a transaction, always roll it back
  229. // regardless of nesting level.
  230. $return = parent::rollBack();
  231. // reset nested transaction count to 0 so that we don't
  232. // try to commit (or rollback) the transaction outside this scope.
  233. $this->nestedTransactionCount = 0;
  234. if ($this->useDebug) {
  235. $this->log('Rollback transaction', null, __METHOD__);
  236. }
  237. }
  238. return $return;
  239. }
  240. /**
  241. * Sets a connection attribute.
  242. *
  243. * This is overridden here to provide support for setting Propel-specific attributes
  244. * too.
  245. *
  246. * @param int $attribute The attribute to set (e.g. PropelPDO::PROPEL_ATTR_CACHE_PREPARES).
  247. * @param mixed $value The attribute value.
  248. */
  249. public function setAttribute($attribute, $value)
  250. {
  251. switch($attribute) {
  252. case self::PROPEL_ATTR_CACHE_PREPARES:
  253. $this->cachePreparedStatements = $value;
  254. break;
  255. default:
  256. parent::setAttribute($attribute, $value);
  257. }
  258. }
  259. /**
  260. * Gets a connection attribute.
  261. *
  262. * This is overridden here to provide support for setting Propel-specific attributes
  263. * too.
  264. *
  265. * @param int $attribute The attribute to get (e.g. PropelPDO::PROPEL_ATTR_CACHE_PREPARES).
  266. */
  267. public function getAttribute($attribute)
  268. {
  269. switch($attribute) {
  270. case self::PROPEL_ATTR_CACHE_PREPARES:
  271. return $this->cachePreparedStatements;
  272. break;
  273. default:
  274. return parent::getAttribute($attribute);
  275. }
  276. }
  277. /**
  278. * Prepares a statement for execution and returns a statement object.
  279. *
  280. * Overrides PDO::prepare() in order to:
  281. * - Add logging and query counting if logging is true.
  282. * - Add query caching support if the PropelPDO::PROPEL_ATTR_CACHE_PREPARES was set to true.
  283. *
  284. * @param string $sql This must be a valid SQL statement for the target database server.
  285. * @param array One or more key => value pairs to set attribute values
  286. * for the PDOStatement object that this method returns.
  287. * @return PDOStatement
  288. */
  289. public function prepare($sql, $driver_options = array())
  290. {
  291. if ($this->useDebug) {
  292. $debug = $this->getDebugSnapshot();
  293. }
  294. if ($this->cachePreparedStatements) {
  295. if (!isset($this->preparedStatements[$sql])) {
  296. $return = parent::prepare($sql, $driver_options);
  297. $this->preparedStatements[$sql] = $return;
  298. } else {
  299. $return = $this->preparedStatements[$sql];
  300. }
  301. } else {
  302. $return = parent::prepare($sql, $driver_options);
  303. }
  304. if ($this->useDebug) {
  305. $this->log($sql, null, __METHOD__, $debug);
  306. }
  307. return $return;
  308. }
  309. /**
  310. * Execute an SQL statement and return the number of affected rows.
  311. *
  312. * Overrides PDO::exec() to log queries when required
  313. *
  314. * @return int
  315. */
  316. public function exec($sql)
  317. {
  318. if ($this->useDebug) {
  319. $debug = $this->getDebugSnapshot();
  320. }
  321. $return = parent::exec($sql);
  322. if ($this->useDebug) {
  323. $this->log($sql, null, __METHOD__, $debug);
  324. $this->setLastExecutedQuery($sql);
  325. $this->incrementQueryCount();
  326. }
  327. return $return;
  328. }
  329. /**
  330. * Executes an SQL statement, returning a result set as a PDOStatement object.
  331. * Despite its signature here, this method takes a variety of parameters.
  332. *
  333. * Overrides PDO::query() to log queries when required
  334. *
  335. * @see http://php.net/manual/en/pdo.query.php for a description of the possible parameters.
  336. * @return PDOStatement
  337. */
  338. public function query()
  339. {
  340. if ($this->useDebug) {
  341. $debug = $this->getDebugSnapshot();
  342. }
  343. $args = func_get_args();
  344. if (version_compare(PHP_VERSION, '5.3', '<')) {
  345. $return = call_user_func_array(array($this, 'parent::query'), $args);
  346. } else {
  347. $return = call_user_func_array('parent::query', $args);
  348. }
  349. if ($this->useDebug) {
  350. $sql = $args[0];
  351. $this->log($sql, null, __METHOD__, $debug);
  352. $this->setLastExecutedQuery($sql);
  353. $this->incrementQueryCount();
  354. }
  355. return $return;
  356. }
  357. /**
  358. * Clears any stored prepared statements for this connection.
  359. */
  360. public function clearStatementCache()
  361. {
  362. $this->preparedStatements = array();
  363. }
  364. /**
  365. * Configures the PDOStatement class for this connection.
  366. *
  367. * @param boolean $suppressError Whether to suppress an exception if the statement class cannot be set.
  368. * @throws PropelException if the statement class cannot be set (and $suppressError is false).
  369. */
  370. protected function configureStatementClass($class = 'PDOStatement', $suppressError = true)
  371. {
  372. // extending PDOStatement is only supported with non-persistent connections
  373. if (!$this->getAttribute(PDO::ATTR_PERSISTENT)) {
  374. $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($class, array($this)));
  375. } elseif (!$suppressError) {
  376. throw new PropelException('Extending PDOStatement is not supported with persistent connections.');
  377. }
  378. }
  379. /**
  380. * Returns the number of queries this DebugPDO instance has performed on the database connection.
  381. *
  382. * When using DebugPDOStatement as the statement class, any queries by DebugPDOStatement instances
  383. * are counted as well.
  384. *
  385. * @return int
  386. * @throws PropelException if persistent connection is used (since unable to override PDOStatement in that case).
  387. */
  388. public function getQueryCount()
  389. {
  390. // extending PDOStatement is not supported with persistent connections
  391. if ($this->getAttribute(PDO::ATTR_PERSISTENT)) {
  392. throw new PropelException('Extending PDOStatement is not supported with persistent connections. Count would be inaccurate, because we cannot count the PDOStatment::execute() calls. Either don\'t use persistent connections or don\'t call PropelPDO::getQueryCount()');
  393. }
  394. return $this->queryCount;
  395. }
  396. /**
  397. * Increments the number of queries performed by this DebugPDO instance.
  398. *
  399. * Returns the original number of queries (ie the value of $this->queryCount before calling this method).
  400. *
  401. * @return int
  402. */
  403. public function incrementQueryCount()
  404. {
  405. $this->queryCount++;
  406. }
  407. /**
  408. * Get the SQL code for the latest query executed by Propel
  409. *
  410. * @return string Executable SQL code
  411. */
  412. public function getLastExecutedQuery()
  413. {
  414. return $this->lastExecutedQuery;
  415. }
  416. /**
  417. * Set the SQL code for the latest query executed by Propel
  418. *
  419. * @param string $query Executable SQL code
  420. */
  421. public function setLastExecutedQuery($query)
  422. {
  423. $this->lastExecutedQuery = $query;
  424. }
  425. /**
  426. * Enable or disable the query debug features
  427. *
  428. * @var boolean $value True to enable debug (default), false to disable it
  429. */
  430. public function useDebug($value = true)
  431. {
  432. if ($value) {
  433. $this->configureStatementClass('DebugPDOStatement', $suppress = true);
  434. } else {
  435. // reset query logging
  436. $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('PDOStatement'));
  437. $this->setLastExecutedQuery('');
  438. $this->queryCount = 0;
  439. }
  440. $this->clearStatementCache();
  441. $this->useDebug = $value;
  442. }
  443. /**
  444. * Sets the logging level to use for logging method calls and SQL statements.
  445. *
  446. * @param int $level Value of one of the Propel::LOG_* class constants.
  447. */
  448. public function setLogLevel($level)
  449. {
  450. $this->logLevel = $level;
  451. }
  452. /**
  453. * Sets a logger to use.
  454. *
  455. * The logger will be used by this class to log various method calls and their properties.
  456. *
  457. * @param BasicLogger $logger A Logger with an API compatible with BasicLogger (or PEAR Log).
  458. */
  459. public function setLogger($logger)
  460. {
  461. $this->logger = $logger;
  462. }
  463. /**
  464. * Gets the logger in use.
  465. *
  466. * @return BasicLogger $logger A Logger with an API compatible with BasicLogger (or PEAR Log).
  467. */
  468. public function getLogger()
  469. {
  470. return $this->logger;
  471. }
  472. /**
  473. * Logs the method call or SQL using the Propel::log() method or a registered logger class.
  474. *
  475. * @uses self::getLogPrefix()
  476. * @see self::setLogger()
  477. *
  478. * @param string $msg Message to log.
  479. * @param int $level (optional) Log level to use; will use self::setLogLevel() specified level by default.
  480. * @param string $methodName (optional) Name of the method whose execution is being logged.
  481. * @param array $debugSnapshot (optional) Previous return value from self::getDebugSnapshot().
  482. */
  483. public function log($msg, $level = null, $methodName = null, array $debugSnapshot = null)
  484. {
  485. // If logging has been specifically disabled, this method won't do anything
  486. if (!$this->getLoggingConfig('enabled', true)) {
  487. return;
  488. }
  489. // If the method being logged isn't one of the ones to be logged, bail
  490. if (!in_array($methodName, $this->getLoggingConfig('methods', self::$defaultLogMethods))) {
  491. return;
  492. }
  493. // If a logging level wasn't provided, use the default one
  494. if ($level === null) {
  495. $level = $this->logLevel;
  496. }
  497. // Determine if this query is slow enough to warrant logging
  498. if ($this->getLoggingConfig("onlyslow", self::DEFAULT_ONLYSLOW_ENABLED)) {
  499. $now = $this->getDebugSnapshot();
  500. if ($now['microtime'] - $debugSnapshot['microtime'] < $this->getLoggingConfig("details.slow.threshold", self::DEFAULT_SLOW_THRESHOLD)) return;
  501. }
  502. // If the necessary additional parameters were given, get the debug log prefix for the log line
  503. if ($methodName && $debugSnapshot) {
  504. $msg = $this->getLogPrefix($methodName, $debugSnapshot) . $msg;
  505. }
  506. // We won't log empty messages
  507. if (!$msg) {
  508. return;
  509. }
  510. // Delegate the actual logging forward
  511. if ($this->logger) {
  512. $this->logger->log($msg, $level);
  513. } else {
  514. Propel::log($msg, $level);
  515. }
  516. }
  517. /**
  518. * Returns a snapshot of the current values of some functions useful in debugging.
  519. *
  520. * @return array
  521. */
  522. public function getDebugSnapshot()
  523. {
  524. if ($this->useDebug) {
  525. return array(
  526. 'microtime' => microtime(true),
  527. 'memory_get_usage' => memory_get_usage($this->getLoggingConfig('realmemoryusage', false)),
  528. 'memory_get_peak_usage' => memory_get_peak_usage($this->getLoggingConfig('realmemoryusage', false)),
  529. );
  530. } else {
  531. throw new PropelException('Should not get debug snapshot when not debugging');
  532. }
  533. }
  534. /**
  535. * Returns a named configuration item from the Propel runtime configuration, from under the
  536. * 'debugpdo.logging' prefix. If such a configuration setting hasn't been set, the given default
  537. * value will be returned.
  538. *
  539. * @param string $key Key for which to return the value.
  540. * @param mixed $defaultValue Default value to apply if config item hasn't been set.
  541. * @return mixed
  542. */
  543. protected function getLoggingConfig($key, $defaultValue)
  544. {
  545. return Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->getParameter("debugpdo.logging.$key", $defaultValue);
  546. }
  547. /**
  548. * Returns a prefix that may be prepended to a log line, containing debug information according
  549. * to the current configuration.
  550. *
  551. * Uses a given $debugSnapshot to calculate how much time has passed since the call to self::getDebugSnapshot(),
  552. * how much the memory consumption by PHP has changed etc.
  553. *
  554. * @see self::getDebugSnapshot()
  555. *
  556. * @param string $methodName Name of the method whose execution is being logged.
  557. * @param array $debugSnapshot A previous return value from self::getDebugSnapshot().
  558. * @return string
  559. */
  560. protected function getLogPrefix($methodName, $debugSnapshot)
  561. {
  562. $prefix = '';
  563. $now = $this->getDebugSnapshot();
  564. $logDetails = array_keys($this->getLoggingConfig('details', array()));
  565. $innerGlue = $this->getLoggingConfig('innerglue', ': ');
  566. $outerGlue = $this->getLoggingConfig('outerglue', ' | ');
  567. // Iterate through each detail that has been configured to be enabled
  568. foreach ($logDetails as $detailName) {
  569. if (!$this->getLoggingConfig("details.$detailName.enabled", false))
  570. continue;
  571. switch ($detailName) {
  572. case 'slow';
  573. $value = $now['microtime'] - $debugSnapshot['microtime'] >= $this->getLoggingConfig("details.$detailName.threshold", self::DEFAULT_SLOW_THRESHOLD) ? 'YES' : ' NO';
  574. break;
  575. case 'time':
  576. $value = number_format($now['microtime'] - $debugSnapshot['microtime'], $this->getLoggingConfig("details.$detailName.precision", 3)) . ' sec';
  577. $value = str_pad($value, $this->getLoggingConfig("details.$detailName.pad", 10), ' ', STR_PAD_LEFT);
  578. break;
  579. case 'mem':
  580. $value = self::getReadableBytes($now['memory_get_usage'], $this->getLoggingConfig("details.$detailName.precision", 1));
  581. $value = str_pad($value, $this->getLoggingConfig("details.$detailName.pad", 9), ' ', STR_PAD_LEFT);
  582. break;
  583. case 'memdelta':
  584. $value = $now['memory_get_usage'] - $debugSnapshot['memory_get_usage'];
  585. $value = ($value > 0 ? '+' : '') . self::getReadableBytes($value, $this->getLoggingConfig("details.$detailName.precision", 1));
  586. $value = str_pad($value, $this->getLoggingConfig("details.$detailName.pad", 10), ' ', STR_PAD_LEFT);
  587. break;
  588. case 'mempeak':
  589. $value = self::getReadableBytes($now['memory_get_peak_usage'], $this->getLoggingConfig("details.$detailName.precision", 1));
  590. $value = str_pad($value, $this->getLoggingConfig("details.$detailName.pad", 9), ' ', STR_PAD_LEFT);
  591. break;
  592. case 'querycount':
  593. $value = $this->getQueryCount();
  594. $value = str_pad($value, $this->getLoggingConfig("details.$detailName.pad", 2), ' ', STR_PAD_LEFT);
  595. break;
  596. case 'method':
  597. $value = $methodName;
  598. $value = str_pad($value, $this->getLoggingConfig("details.$detailName.pad", 28), ' ', STR_PAD_RIGHT);
  599. break;
  600. default:
  601. $value = 'n/a';
  602. break;
  603. }
  604. $prefix .= $detailName . $innerGlue . $value . $outerGlue;
  605. }
  606. return $prefix;
  607. }
  608. /**
  609. * Returns a human-readable representation of the given byte count.
  610. *
  611. * @param int $bytes Byte count to convert.
  612. * @param int $precision How many decimals to include.
  613. * @return string
  614. */
  615. protected function getReadableBytes($bytes, $precision)
  616. {
  617. $suffix = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
  618. $total = count($suffix);
  619. for ($i = 0; $bytes > 1024 && $i < $total; $i++)
  620. $bytes /= 1024;
  621. return number_format($bytes, $precision) . ' ' . $suffix[$i];
  622. }
  623. /**
  624. * If so configured, makes an entry to the log of the state of this object just prior to its destruction.
  625. * Add PropelPDO::__destruct to $defaultLogMethods to see this message
  626. *
  627. * @see self::log()
  628. */
  629. public function __destruct()
  630. {
  631. if ($this->useDebug) {
  632. $this->log('Closing connection', null, __METHOD__, $this->getDebugSnapshot());
  633. }
  634. }
  635. }