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 914609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:44:43+00:00 2026-05-15T17:44:43+00:00

I have to insert some data into a MySQL table. The data will be

  • 0

I have to insert some data into a MySQL table. The data will be retrieved and then (at present) unserialized at which point the correct display language will be selected…

I’ve managed to munge the data (text encoded with markdown) into a set of PHP statements, roughly along the following lines:

<?php
$component_data = array();
$component_data[65] =
  array( // reformatted to avoid side-scrolling
      "en"=>"* Student welfare is our top priority.\n* We 
               have 30 years of experience of running successful 
               courses for Young Learners.",
      "es"=>"* El bienestar de nuestros estudiantes es nuestra 
               principal prioridad.\n* Contamos con experiencia de 
               30 años de exitosa realización de cursos para jóvenes.",
      "de"=>"* Das Wohl des Lernenden ist unsere oberste Priorität.\n 
               *Wir organisieren seit 30 Jahren erfolgreich 
               Sprachkurse für Jugendliche",
      "it"=>"* Il benessere degli studenti è la nostra priorità 
               assoluta.\n* Abbiamo 30 anni di esperienza nei corsi 
               per ragazzi.",
      "fr"=>"* Le bien-être de l’élève a pour nous la priorité absolue.
             \n* Nous avons 30 ans d'expérience dans la gestion de cours 
             réussis pour jeunes étudiants");
?>

and I was hoping to use the following to get it into a format ready for import into the MySQL table:

<?php
    foreach ($component_data as $id => $value) {
      echo "UPDATE `components` SET `component_content`='".
        mysql_real_escape_string(serialize($value)).
        "' WHERE `id` = '$id';\n";
    }
?>

Unfortunately it does go in, but the result on the page is mangled, i.e. it just shows the serialised string, rather than the array (which is the default behaviour if it can’t managed to unserialise the string fetched from MySQL).

I’ve tried a number of permutations of the PHP string cleaning functions, and my head is frankly spinning.

Ideally, I’d like to be able to reformat the PHP styled data for insertion into the MySQL db, so that when fetched it’s still in an unserializable state…

… and for bonus points, if you can convert the utf8 foreign language chars to HTML entitities and from markdown into HTML

  • 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-05-15T17:44:44+00:00Added an answer on May 15, 2026 at 5:44 pm

    Thanks to everyone for their useful suggestions.

    Actually, the problem turned out to be the mixture of stored textile (not markdown!) and multi-lingual utf-8. The solution to squeezing it into MySQL was a bit crufty. First run textile over the dataset to get it into html, and then munge it through the following, to handle encoding the foreign characters:

    <?php
    include 'data.php'; // contains component data similar to above.
    
    foreach ($component_data as $id => $value) {
      foreach ($value as $language => $translation) {
        $value[$language] = str_replace(
          array("&lt;","&gt;"),
          array('<','>'), 
          htmlentities($translation, ENT_NOQUOTES, "UTF-8")
          );
      }
      echo "UPDATE `components` SET `component_content`='".mysql_real_escape_string(serialize($value))."' WHERE `id` = '$id';\n";
    }
    
    ?>
    

    The important bit was the ENT_NOQUOTES which meant a simple str_replace could deal with open and closing tags (no maths in the text thankfully), and the mysql_real_escape_string could handle the single quotes. Glad that’s over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that is trying to insert some data into an SQL
I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I am trying to write a function that will insert data into a MySQL
i have some large SQL-Files with many INSERT INTO Statements. My Command: mysql> Load
I have a MySQL insert statement that inserts data from an existing Despgoods table
I have s MySQL database and I need to insert some specific data in
Scenario: I have multiple text boxes in which a user will enter data into
I have following piece of code which posts some data into database: $post =
I have a JPA project and I would like to insert some initial data
I have some data enclosed in HTML tags. I want to insert this data

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.