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

  • Home
  • SEARCH
  • 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 8651027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:57:44+00:00 2026-06-12T13:57:44+00:00

I use php serialize() to serialize an array. Then I put it in the

  • 0

I use php serialize() to serialize an array. Then I put it in the database (column type text). My array contains other language character like chinese or japanese characters.

It is able to serialize and store it in database correctly however, when I obtain the serialized array out of database and unserialize it so I can use the array, it won’t work, the unserialize array will just be blank.

here’s my code,
Save script:

$all = array (
    "points" => '123',
    "photo" => '写真',
    "video" => 'video'
);

$sall = serialize($all);

mysql_query("UPDATE users SET lang = '$sall' WHERE uname='$uname'")
    or die(mysql_error()); 

Retrieve script:

$result = mysql_query("SELECT * FROM users WHERE uname='$uname'")
    or die(mysql_error());

$row = mysql_fetch_array($result);

if($row) {
    $lang = $row['lang'];
    $orilang = unserialize($lang);
    // orilang contains the array
    echo $orilang['photo'];
}
else {

}

$orilang['photo'] came out empty but $lang has the serialized data.

  • 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-12T13:57:45+00:00Added an answer on June 12, 2026 at 1:57 pm

    As serialize() is not binary safe I’d suggest you to use json to encode you data:

    $all = array (
        "points" => '123',
        "photo" => '写真',
        "video" => 'video'
    );
    $sall = json_encode($all);
    // {"points":"123","photo":"\u5199\u771f","video":"video"}
    
    $decode = json_decode($sall, true);
    
    /*array(3) {
      ["points"]=>
      string(3) "123"
      ["photo"]=>
      string(6) "写真"
      ["video"]=>
      string(5) "video"
    }*/
    

    As a side note, if you started building something I’d suggest you move to MySQLi or PDO, mysql_* functions are deprecated. Here is a nice tutorial to get you started on PDO.

    To get results:

    $result = mysql_query("SELECT * FROM users WHERE uname='$uname'")
        or die(mysql_error());
    
    $row = mysql_fetch_assoc($result);
    
    if($row) {
        $lang = $row['lang'];
        $orilang = json_decode($lang, true);
        // orilang contains the array
        echo $orilang['photo'];
    
        // or
        // $orilang = json_decode($lang);
        // echo $orilang->photo;
    
    } else {
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use php to display a table of data drawn from my mysql database.
Use PHP and Mysql. Fields in my table (product) are id , full_price ,
I use php with ajax. <?php /* * Suppose, user has entered both correct
I am trying to use PHP to fire hits at Google to track newsletter
I am trying to use PHP Curl to make the registrations of https://www3.gotomeeting.com/register/432624022 automatic.
I need to do use php/regex to replace this: {{image-4-m}} to this: <img src=4.jpg
I can't use PHP in my HTML pages. For example, index.html . I've tried
I'm trying to use PHP's split() (preg_split() is also an option if your answer
I want to use PHP to replace javascript functions in HTML documents. For example:
When i use php include to include a page in my website all the

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.