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.
Shamsul KamalJunior TechAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Shamsul KamalJunior TechAuthor 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.
Chris StanyonWebDevCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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";
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.