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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:24:46+00:00 2026-06-11T14:24:46+00:00

I have an XML file with data from a latin1 encoded, latin1_swedish_ci collated table

  • 0

I have an XML file with data from a latin1 encoded, latin1_swedish_ci collated table that I want to transfer to another mysql table. I have set up the destination table with the same encodings. I query the database for each row of the table and I end up with all the special characters messed up. I have also set the encoding in the XML file <?xml version="1.0" encoding="latin1" ?>. Can it be a problem of PHP? Do I have to set up the encoding somewhere else:

Here is my script:

    // create table courses if not exists
echo("Creating new tables...\n");
if (!mysql_query("CREATE TABLE IF NOT EXISTS members (
    id int(11) NOT NULL,
    isfg_no int(11) NOT NULL,
    lab_id int(11) NOT NULL,
    first varchar(256) NOT NULL,
    last varchar(512) NOT NULL,
    PRIMARY KEY (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1"))
    die(mysql_error());

    // load xml file
echo "Loading XML file...\n";
$members = simplexml_load_file("members.xml");

foreach ($members as $row) {
    $id = mysql_real_escape_string($row->SO_IdSocio);
    $isfg_no = mysql_real_escape_string($row->SO_Numisfg);
    $lab_id = mysql_real_escape_string($row->SO_Numlab);
    $first = mysql_real_escape_string($row->SO_Nombre);
    $last = mysql_real_escape_string($row->SO_Apellidos);

    if (!mysql_query("INSERT INTO members (id, isfg_no, lab_id, first, last)VALUES ('$id', '$isfg_no', '$lab_id', '$first', '$last')")) 
        die(mysql_error());
}

Here is some of the XML

<?xml version="1.0" encoding="latin1" ?>
<SOCIOS_INTRA>
<row>
    <SO_IdSocio>1</SO_IdSocio>
    <SO_Numsocio>001</SO_Numsocio>
    <SO_Numisfg>404</SO_Numisfg>
    <SO_Nombrelab>SIN LABORATORIO</SO_Nombrelab>
    <SO_Numlab>0</SO_Numlab>
    <SO_Nombre>******</SO_Nombre>
    <SO_Apellidos>*******</SO_Apellidos>
    <SO_Direccion>C/Recoletos 22, 3ª planta</SO_Direccion>
    <SO_Cp>28001</SO_Cp>
    <SO_Poblacion>Madrid</SO_Poblacion>
    <SO_Provincia>Madrid</SO_Provincia>
    <SO_Idpais>25</SO_Idpais>
    <SO_Email1>*******</SO_Email1>
    <SO_Email2></SO_Email2>
    <SO_Telefono>***</SO_Telefono>
    <SO_Fax>****</SO_Fax>
    <SO_Login></SO_Login>
    <SO_Password></SO_Password>
    <SO_Fecha>19960101</SO_Fecha>
    <SO_SituacionISFG>0</SO_SituacionISFG>
    <SO_SituacionGEP>1</SO_SituacionGEP>
    <SO_Observaciones></SO_Observaciones>
</row>
  • 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-11T14:24:47+00:00Added an answer on June 11, 2026 at 2:24 pm

    You don’t need to set encoding in PHP. You should use SET NAMES 'latin1' as first SQL-statement.

    UPDATE:

    I think that you have misconfigured server. I have run this code and all works perfectly

    <?php
    
    $lnk=mysql_connect('localhost', 'root', '');
    mysql_select_db('test', $lnk);
    
    echo("Creating new tables...\n");
    if (!mysql_query("CREATE TABLE IF NOT EXISTS members (
        id int(11) NOT NULL,
        isfg_no int(11) NOT NULL,
        lab_id int(11) NOT NULL,
        first varchar(256) NOT NULL,
        last varchar(512) NOT NULL,
        PRIMARY KEY (id)
        ) ENGINE=InnoDB DEFAULT CHARSET=latin1"))
        die(mysql_error());
    
        // load xml file
    echo "Loading XML file...\n";
    $members = simplexml_load_file("members.xml");
    
    foreach ($members as $row) {
        $id = mysql_real_escape_string($row->SO_IdSocio);
        $isfg_no = mysql_real_escape_string($row->SO_Numisfg);
        $lab_id = mysql_real_escape_string($row->SO_Numlab);
        $first = mysql_real_escape_string($row->SO_Nombre);
        $last = mysql_real_escape_string($row->SO_Apellidos);
    
        if (!mysql_query("INSERT INTO members (id, isfg_no, lab_id, first, last)VALUES ('$id', '$isfg_no', '$lab_id', '$first', '$last')")) 
            die(mysql_error());
        else
            print("INSERT INTO members (id, isfg_no, lab_id, first, last)VALUES ('$id', '$isfg_no', '$lab_id', '$first', '$last')<br />");
    }
    
    ?>
    

    and this XML

    <?xml version="1.0" encoding="latin1" ?>
    <SOCIOS_INTRA>
    <row>
        <SO_IdSocio>2</SO_IdSocio>
        <SO_Numsocio>001</SO_Numsocio>
        <SO_Numisfg>404</SO_Numisfg>
        <SO_Nombrelab>SIN LABORATORIO</SO_Nombrelab>
        <SO_Numlab>0</SO_Numlab>
        <SO_Nombre>******</SO_Nombre>
        <SO_Apellidos>*******</SO_Apellidos>
        <SO_Direccion>C/Recoletos 22, 3ª planta</SO_Direccion>
        <SO_Cp>28001</SO_Cp>
        <SO_Poblacion>Madrid</SO_Poblacion>
        <SO_Provincia>Madrid</SO_Provincia>
        <SO_Idpais>25</SO_Idpais>
        <SO_Email1>*******</SO_Email1>
        <SO_Email2></SO_Email2>
        <SO_Telefono>***</SO_Telefono>
        <SO_Fax>****</SO_Fax>
        <SO_Login></SO_Login>
        <SO_Password></SO_Password>
        <SO_Fecha>19960101</SO_Fecha>
        <SO_SituacionISFG>0</SO_SituacionISFG>
        <SO_SituacionGEP>1</SO_SituacionGEP>
        <SO_Observaciones></SO_Observaciones>
    </row><row>
        <SO_IdSocio>3</SO_IdSocio>
        <SO_Numsocio>001</SO_Numsocio>
        <SO_Numisfg>404</SO_Numisfg>
        <SO_Nombrelab>SIN LABORATORIO</SO_Nombrelab>
        <SO_Numlab>0</SO_Numlab>
        <SO_Nombre>******</SO_Nombre>
        <SO_Apellidos>*******</SO_Apellidos>
        <SO_Direccion>C/Recoletos 22, 3ª planta</SO_Direccion>
        <SO_Cp>28001</SO_Cp>
        <SO_Poblacion>Madrid</SO_Poblacion>
        <SO_Provincia>Madrid</SO_Provincia>
        <SO_Idpais>25</SO_Idpais>
        <SO_Email1>*******</SO_Email1>
        <SO_Email2></SO_Email2>
        <SO_Telefono>***</SO_Telefono>
        <SO_Fax>****</SO_Fax>
        <SO_Login></SO_Login>
        <SO_Password></SO_Password>
        <SO_Fecha>19960101</SO_Fecha>
        <SO_SituacionISFG>0</SO_SituacionISFG>
        <SO_SituacionGEP>1</SO_SituacionGEP>
        <SO_Observaciones></SO_Observaciones>
    </row>
    </SOCIOS_INTRA>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a XML File i want to insert data from that XML file
I have a flash file that is loading data from XML file. After I
I have one problem , I want to get some data from XML file
I have an XML file and I want to retrieve data from it so
I have an XML file in which I want to extract data from certain
I have xml file with data that i have to display in table. Now
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have an xml file(from federal government's data.gov) which I'm trying to read with
I have an xml data file and I want to populate a listview in
I have a XML-file, which contains the data of a calendar. I want to

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.