How to create PHP script to modify the following value stored in MYSQL database ?


I would like to request an assistant.

I have a database name "internet_online" and a mysql table name "package_queue" .

In column "queue_array" exist the following value :


I would like to change the : to

and to

May i know how to do that using PHP ?

I do not know what is this queue_array format and need assistant on this.

Thank you.
Who is Participating?
Chris StanyonCommented:
Yes. Your data is serialized, so you use unserialize($data) to return an array. You then change your values in the array and re-serialize before storing back in your database:

$queue = unserialize($queue_array);
$queue['ns1'] = 'some new value';
$queue['ns2'] = 'some new value';
$newQueue = serialize($queue);
//And then:
$sqlStr = "UPDATE package_queue SET queue_array = '$newQueue' WHERE xx = yy";

Open in new window

The one thing I'd say though is you need to step away from using the mysql* library. It's now deprecated and you'll need to switch to either mysqli or PDO.
Not sure what you want to change it to so just replace new-value below with the value you want to change it to

You don't need to do this in PHP per se, you can just run the following SQL directly against the database
UPDATE package_queue set queue_array = REPLACE(queue_array, " to", "new-value")

Open in new window

smksaAuthor Commented:
Actually , this value will keep on changing, and need to find out how to solve this.

After doing research , i found out that this queue_array  is the unserialize .

Can anybody confirm that the following will works ?

$sql = "Select queue_array from package_queue";
$getdata = mysql_query($sql);

while (list($id, $queue_array) = mysql_fetch_row($getdata)) {
    if (stristr($queue_array, "inv_id")) {
        $queue = unserialize($queue_array);
        $ns1 = $queue["ns1"];
        $ns2 = $queue["ns2"];

Then i can use $ns1 & $ns2 to change this value right ?

Can anybody confirm this  or complete the query ?
Yes that will work as well.
Ray PaseurCommented:
Here's how to make the required move away from MySQL.

Your SELECT query might need to be like this (so you have the id for the update):
$sql = "Select id, queue_array from package_queue";

Your UPDATE query would probably be something like this:
$sql = "UPDATE package_queue SET queue_array = '$newQueue' WHERE id = $id LIMIT 1";
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.