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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:05:18+00:00 2026-05-27T12:05:18+00:00

When I execute the code below, mysql_connect(localhost, user, pass) or die(Could not connect: .

  • 0

When I execute the code below,

mysql_connect("localhost", "user", "pass") or die("Could not connect: " . mysql_error());
mysql_select_db("database");
mysql_query ("set character_set_results='utf8'");
$result = mysql_query("SELECT xxx");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  $str = $row[0];
  echo $str;
}

I got the message below if I check the sources(Chinese words, UTF-8 encoding as below),

LS23A300BS(23”LED顯示器)/ LS22A300BS(21.5”LED顯示器)

But, when I added the code to convert the SQL result to XML file as below,

$dom = new domDocument;
$dom->formatOutput = true;

$root = $dom->appendChild($dom->createElement( "items" ));
$sxe = simplexml_import_dom($dom);

mysql_connect("localhost", "user", "pass") or die("Could not connect: " . mysql_error());
mysql_select_db("database");
mysql_query ("set character_set_results='utf8'");
$result = mysql_query("SELECT xxx");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
  $item = $sxe->addChild("item");
  $str = $row[0];  
  $item->addChild("desc", $str);
}

echo $sxe->asXML();

mysql_free_result($result);

I got the message below if I check the sources (unknown encoding as below),

LS23A300BS(23”LED顯示器)/ LS22A300BS(21.5”LED顯示器)

I want to ask,
What is the type of the unknown encoding?
How can I change this unknown encoding back to UTF-8?

Thanks

  • 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-27T12:05:18+00:00Added an answer on May 27, 2026 at 12:05 pm

    Two things to try:

    1. Use mysql_query('SET NAMES utf8'); instead of character_set_results. This sets a few more key MySQL settings to utf8.
    2. You don’t declare the encoding of your DOMDocument. Try using this as your constructor: new DOMDocument('1.0', 'UTF-8')

    This is an aside: You don’t need DOMDocument at all here. Try $sxe = simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><items/>');

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

Sidebar

Related Questions

When I execute the code saveXML below it generates the error above, why?? using
I get the following error when I try and execute the code down below.
The PHP Mongo Driver allows me to execute code in the database. Does this
The code below worked on my old iMac with MAMP. However, it does not
I am trying out prepared statements, but the below code is not working. I
I am testing the code below, does a basic database query. It works fine
Suppose I want to execute code, for example value += 5 inside a namespace
Is there any online complier/interpreter to execute code for php 5.3? like there is
I'm building a node server that needs to execute code that might be unsafe.
I have an event handler that needs to determine a type and execute code

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.