Announcement

Collapse
No announcement yet.

Little code to convert db and all tables to utf8 or an other charset

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Little code to convert db and all tables to utf8 or an other charset

    Hi,

    Hereby a little code to convert db and all tables to utf8 or an other charset, if someone need it

    Nac

    -----------------------

    $database={db_name};

    $alter_database_charset_sql = "ALTER DATABASE ".$database." CHARACTER SET utf8 COLLATE utf8_unicode_ci";
    sc_exec_sql($alter_database_charset_sql,"conn_mysq l");

    sc_lookup(rs, "SHOW TABLES");
    if ({rs} === false)
    {
    echo "Access error. Message=". {rs_erro} ;
    }
    elseif (empty({rs}))
    {
    echo "Select command didn't return data";
    }
    else
    {
    $i=0;
    while (isset({rs[$i][0]})){
    $mtable = {rs[$i][0]};

    $alter_table_sql = "ALTER TABLE ".$mtable." CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci";
    sc_exec_sql($alter_table_sql,"conn_mysql");

    echo "<pre>";
    var_dump($mtable);
    echo "</pre>";

    $i++;
    }
    }

  • #2
    Thanks for share

    BTW, you can do this, on HeidiSQL, with "Massive Edit Table" (for MySQL and MariaDB)
    /Giuseppe

    Professional Scriptcase Services
    Some Customers opinions

    Comment


    • #3
      Originally posted by Giu View Post
      Thanks for share

      BTW, you can do this, on HeidiSQL, with "Massive Edit Table" (for MySQL and MariaDB)
      Very nice! Copied it to the faq's on scriptcase.eu
      Albert Drent
      aducom software netherlands
      scriptcase partner, reseller, support and (turn-key) development
      www.scriptcase.eu / www.scriptcase.nl

      Comment

      Working...
      X