Source Rally PHP Community Scripts .. Sign up .. Login
A script to convert columns in a mysql-table to utf8 unicode columns. Needs some modding though.
Access: Public      Tags: utf8, mysql, php
Add to favourites       Subscribe comments       Copy code       Bookmark
<?
        
function utf8()
    {
                
$database 'db_name';
        
$r = new query('select 1');
        
$r->resource mysql_list_tables($database);
        if(
$r->num_rows()>0)
        {
            while(
$row $r->fetch_array())
            {
                
$tableName $row['Tables_in_'.$database];
                
$sql "SHOW COLUMNS FROM ".slash($tableName);
                
$r1 = new query($sql);
                while(
$row $r1->fetch_array())
                {
                    
//dump($row);
                    
if(substr($row['Type'],0,7)=='varchar'
                    
||
                    
$row['Type']=='text'
                    
||
                    
$row['Type']=='longtext'
                    
||
                    
substr($row['Type'],0,4)=='char'
                    
)
                    {
                         
$sql "ALTER TABLE `".slash($tableName)."` CHANGE `".slash($row['Field'])."` `".slash($row['Field'])."` ".slash($row['Type'])." CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL";
                         echo 
$sql.'<br/>';
                         
mysql_query($sql);
                     }
                
//     mysql_query($sql);
                
}
            }
        }
    }
?>
Add to favourites       Subscribe comments       Copy code       Bookmark
Sign up to add your own comment here!

Shared by:

regin

Mail user Add to friends
All user contributed content is available under the LGPL unless specified otherwise.
Remaining copyrights Regin Gaarsmand © 2006-2008
About SourceRally.net
Adelgazar sin trucos Programador PHP