[Solar-talk] UTF-8

Paul M Jones pmjones at solarphp.com
Thu Jul 20 10:12:27 PDT 2006


On Jul 20, 2006, at 12:04 PM, Rodrigo Moraes wrote:

> Working with Solar_Sql and UTF-8 tables: I've added the method
> _connect() to Solar_Sql_Adapter_Mysql:
>
>     protected function _connect()
>     {
>         parent::_connect();
>         if(isset($this->_config['charset'])) {
>             $this->_pdo->exec('SET CHARACTER SET ' . $this->_config 
> ['charset']);
>         }
>     }
>
> And a charset definition in config.php:
>
> $config['Solar_Sql'] = array(
>     'adapter' => 'Solar_Sql_Adapter_Mysql',
>     'config'  => array(
>         ...
>         'charset' => 'utf8',
>     )
> );
>
> Works perfectly. :-)


That's pretty cool.  :-)

I probably won't put it in the standard adapters just yet; at least,  
not until we have a way of doing it that extends across all  
adapters.  I want them all to work as close to identically as  
possible (and they're pretty near identical right now).

Having said that, so that your code doesn't disappear on the next  
Solar release, you may wish to extend that adapter and make your own:

Solar::loadlClass('Solar_Sql_Adapter_Mysql');
class Tipos_Sql_Adapter_Mysql extends Solar_Sql_Adapter_Mysql {
     protected function _connect()
     {
         parent::_connect();
         if(isset($this->_config['charset'])) {
             $this->_pdo->exec('SET CHARACTER SET ' . $this->_config 
['charset']);
         }
     }
}

Then you can specify $config['Solar_Sql'] = array('adapter' =>  
'Tipos_Sql_Adapter_Mysql', ...).


--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.   <http://solarphp.com>

Savant: The simple, elegant, and powerful solution for
templates in PHP.   <http://phpsavant.com>




More information about the solar-talk mailing list