Packages

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

Classes

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