Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • MsSqlDriver
  • MySqlDriver
  • OciDriver
  • OdbcDriver
  • PgSqlDriver
  • Sqlite2Driver
  • SqliteDriver
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Database\Drivers;
 13: 
 14: use Nette;
 15: 
 16: 
 17: 
 18: /**
 19:  * Supplemental MySQL database driver.
 20:  *
 21:  * @author     David Grudl
 22:  */
 23: class MySqlDriver extends Nette\Object implements Nette\Database\ISupplementalDriver
 24: {
 25:     /** @var array */
 26:     public $supports = array('meta' => TRUE);
 27: 
 28:     /** @var Nette\Database\Connection */
 29:     private $connection;
 30: 
 31: 
 32: 
 33:     /**
 34:      * Driver options:
 35:      *   - charset => character encoding to set (default is utf8)
 36:      *   - sqlmode => see http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
 37:      */
 38:     public function __construct(Nette\Database\Connection $connection, array $options)
 39:     {
 40:         $this->connection = $connection;
 41:         $charset = isset($options['charset']) ? $options['charset'] : 'utf8';
 42:         if ($charset) {
 43:             $connection->exec("SET NAMES '$charset'");
 44:         }
 45:         if (isset($options['sqlmode'])) {
 46:             $connection->exec("SET sql_mode='$options[sqlmode]'");
 47:         }
 48:         $connection->exec("SET time_zone='" . date('P') . "'");
 49:     }
 50: 
 51: 
 52: 
 53:     /********************* SQL ****************d*g**/
 54: 
 55: 
 56: 
 57:     /**
 58:      * Delimites identifier for use in a SQL statement.
 59:      */
 60:     public function delimite($name)
 61:     {
 62:         // @see http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
 63:         return '`' . str_replace('`', '``', $name) . '`';
 64:     }
 65: 
 66: 
 67: 
 68:     /**
 69:      * Formats date-time for use in a SQL statement.
 70:      */
 71:     public function formatDateTime(\DateTime $value)
 72:     {
 73:         return $value->format("'Y-m-d H:i:s'");
 74:     }
 75: 
 76: 
 77: 
 78:     /**
 79:      * Encodes string for use in a LIKE statement.
 80:      */
 81:     public function formatLike($value, $pos)
 82:     {
 83:         $value = addcslashes(str_replace('\\', '\\\\', $value), "\x00\n\r\\'%_");
 84:         return ($pos <= 0 ? "'%" : "'") . $value . ($pos >= 0 ? "%'" : "'");
 85:     }
 86: 
 87: 
 88: 
 89:     /**
 90:      * Injects LIMIT/OFFSET to the SQL query.
 91:      */
 92:     public function applyLimit(&$sql, $limit, $offset)
 93:     {
 94:         if ($limit >= 0 || $offset > 0) {
 95:             // see http://dev.mysql.com/doc/refman/5.0/en/select.html
 96:             $sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
 97:                 . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
 98:         }
 99:     }
100: 
101: 
102: 
103:     /**
104:      * Normalizes result row.
105:      */
106:     public function normalizeRow($row, $statement)
107:     {
108:         return $row;
109:     }
110: 
111: }
112: 
Nette Framework 2.0beta1 API API documentation generated by ApiGen 2.3.0