Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7767803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:45:53+00:00 2026-06-01T15:45:53+00:00

Due to errors of my predecessors a (MySQL) database I would like to use

  • 0

Due to errors of my predecessors a (MySQL) database I would like to use contains a lot of HTML entities (e.g. € instead of €).

As the database should contain raw data (a database shouldn’t have anything to do with HTML) I want to remove them from the DB and store it in proper UTF8, the collocation is already that.

What would be a good way to fix this? The only thing I can think of is to write a PHP script that gets all the data, runs it through html_entity_decode() and writes it back. It’s doable since it’s a one-time-operation and the DB is only about 100MB large, but it’s still less than optimal.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:45:55+00:00Added an answer on June 1, 2026 at 3:45 pm

    Since no-one could provide a satisfying SQL-only solution, I solved it with a script similar to this one.
    Note that it only works if all the tables you use it on have a primary key, but this will usually be the case

    <?php
    // Specify which columns need to be de-entitiezed
    $affected = array(
        'table1' => array('column1', 'column2'),
        'table2' => array('column1', 'column2'),
    );
    
    // Make database connection
    $db = new PDO("mysql:dbname=yourdb;host=yourhost", "user", "pass");
    
    foreach($affected as $table => $columns){
        // Start a transaction for each table
        $db->beginTransaction();
    
        // Find the table primary key. PHP5.4 syntax!
        $pk = $db->query("SHOW INDEX FROM " . $table . " WHERE Key_name = 'PRIMARY'")->fetch()[0];
    
        foreach($columns as $column){
            // Construct a prepared statement for this column
            $ps = $db->prepare("UPDATE " . $table . " SET " . $column . " . = ? WHERE " . $pk . " = ?");
    
            // Go through all rows
            foreach( $db->query("SELECT " . $column . ", " . $pk . " FROM " . $table) as $row){
                $row[0] = html_entity_decode($row[0]);  // Actual processing
                $ps->execute($row);
            }
        }
    
        // Everything went well for this table, commit
        $db->commit();
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to catch errors (for instance due to timeout) with net-snmp in
I use Aptana to write Python code. Aptana often report error due to the
I am getting disturbing errors due to issues on primary keys and inserting values
I would like to have all my data on a server be streamed into
i want to backup firebird database. Below is command that i use to execute
My application exits for no reason, most likely due to errors in the profiler
Possible Duplicate: Resolve build errors due to circular dependency amongst classes I am pretty
I was just doing some validation and got some errors due to my javascript...
I would like to run some code on the Python version of Google App
Due to repetitive errors with one of our Java applications: Engine engine_0: Error in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.