Вход Регистрация
Файл: vendor/doctrine/dbal/lib/Doctrine/DBAL/Event/Listeners/MysqlSessionInit.php
Строк: 85
<?php

namespace DoctrineDBALEventListeners;

use 
DoctrineCommonEventSubscriber;
use 
DoctrineDBALEventConnectionEventArgs;
use 
DoctrineDBALEvents;

/**
 * MySQL Session Init Event Subscriber which allows to set the Client Encoding of the Connection.
 *
 * @deprecated Use "charset" option to PDO MySQL Connection instead.
 */
class MysqlSessionInit implements EventSubscriber
{
    
/**
     * The charset.
     *
     * @var string
     */
    
private $charset;

    
/**
     * The collation, or FALSE if no collation.
     *
     * @var string|bool
     */
    
private $collation;

    
/**
     * Configure Charset and Collation options of MySQL Client for each Connection.
     *
     * @param string      $charset   The charset.
     * @param string|bool $collation The collation, or FALSE if no collation.
     */
    
public function __construct($charset 'utf8'$collation false)
    {
        
$this->charset   $charset;
        
$this->collation $collation;
    }

    
/**
     * @return void
     */
    
public function postConnect(ConnectionEventArgs $args)
    {
        
$collation $this->collation ' COLLATE ' $this->collation '';
        
$args->getConnection()->executeStatement('SET NAMES ' $this->charset $collation);
    }

    
/**
     * {@inheritdoc}
     */
    
public function getSubscribedEvents()
    {
        return [
Events::postConnect];
    }
}
Онлайн: 1
Реклама