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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:39:45+00:00 2026-05-25T16:39:45+00:00

I have a simple PHP script to extract data from a mySQL database and

  • 0

I have a simple PHP script to extract data from a mySQL database and encode it as JSON. The problem is that special characters (for example German ä or ß characters) are stripped from the JSON response. Everything after the first special character for any single field is just stripped.

The fields are set to utf8_bin, and in phpMyAdmin the characters display correctly.

The PHP script looks like this:

<?php
header("Content-type: application/json; charset=utf-8");

$con = mysql_connect('database', 'username', 'password');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sql01_5789willgil", $con);

$sql="SELECT * FROM weightevent";

$result = mysql_query($sql);
$row = mysql_fetch_array($result);

$events = array();

while($row = mysql_fetch_array($result))
{
 $eventid = $row['eventid'];
 $userid = $row['userid'];
 $weight = $row['weight'];
 $sins = $row['sins'];
 $gooddeeds = $row['gooddeeds'];
 $date = $row['date'];
 $event = array("eventid"=>$eventid, "userid"=>$userid, "weight"=>$weight, "sins"=>$sins, 
 "gooddeeds"=>$gooddeeds, "date"=>$date);
 array_push($events, $event);
}

$myJSON = json_encode($events);

echo $myJSON;

mysql_close($con);
?>

Sample output:

[{"eventid":"2","userid":"1","weight":"70.1","sins":"Weihnachtspl","gooddeeds":"situps! lots and lots of situps!","date":"2011-01-02"},{"eventid":"3","userid":"2","weight":"69.9","sins":"A second helping of pasta...","gooddeeds":"I ate lots of salad","date":"2011-01-01"}]

–> in the first record the value for field ‘sins’ should be “Weihnachtsplätzchen”.

thanks very much!

  • 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-25T16:39:46+00:00Added an answer on May 25, 2026 at 4:39 pm

    mysql_set_charset("utf8"); right after mysql_connect

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

Sidebar

Related Questions

I have a simple php/mysql script that stores in mysql database id, link, and
I have a simple PHP mailer script that takes values from a form submitted
I have a simple php script on a server that's using fsockopen to connect
I have a simple php script on my domain that sends me an email:
I have a simple PHP script that will either serve up a streaming ASF
I have an extremely simple script with PHP exec , calling mysql command: $dbhost
I have a simple feedback form PHP script that I would like to enhance
I have a simple PHP script that sends a message to a specified email
So I have a url from where I extract the data with extracthtml.php :
I have a problem with the JSON result of my PHP script. I can't

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.