Convert latin1 to utf8

db, development, mysql Comments Off on Convert latin1 to utf8

If you import unicode text into latin1 database column, the symbols would be screwed up — russian symbols become a shit like “залоговый депозит”.

To convert such quickly (as a test) you can use Lebedev’s convertor.

To convert the whole table do the following (thanks to dull.ru):

  1. The most important step: dump such data in a file with mysqldump
    mysqldump -u user -p --default-character-set=latin1 --skip-set-charset --no-create-info --extended-insert --complete-insert dbname table > dbname.sql

    If not the whole table data is bad, create another table (CREATE TABLE t2 LIKE t1) and copy wrong rows to the new table.

  2. Replace latin1 by utf8 in the file
    This can be done manually in your editor or by this command:

    sed -r 's/latin1/utf8/g' dbname.sql > dbname_utf.sql
  3. Convert your latin1-table to utf8 (and maybe truncate it):
    ALTER TABLE `table` CONVERT TO CHARACTER SET 'utf8';
  4. Import the utf8 data back to the table:
    mysql -u user -p --default-character-set=utf8 dbname < dbname_utf.sql

That’s it.

Zend View Helpers inheritance

development, php, plugin, zend Comments Off on Zend View Helpers inheritance

It’s handy to use View Helpers in Zend FW driven project. For example, you want to make an in-place tracker (e.g. Google Analytics) — you create a helper class My_View_Helper_Tracker inherited from Zend_View_Helper, Zend finds its automatically and then you are free to use your helper method:

echo $this->tracker( $trackerID );

The question is what you gonna do if you want a base class for a family of trackers?

It’s not so obvoius due to naming conventions.

Let’s say you want 2 kinds of trackers: Google Analytics and Euroads.

1. You create such files structure:


library
 - My
   - View 
    - Helper
      - Tracker
        Abstract.php
        - Google
          Page.php
        - Euroads
          Owner.php
          Guest.php

2. You name your classes as:

  • My_View_Helper_Tracker_Euroads_Guest (extends My_View_Helper_Tracker_Abstract)
  • … so on …

3. Class methods are:

public function tracker_euroads_guest(...) ...

4. And the trickiest part: the helper call:

echo $this->tracker_Euroads_Guest
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in