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

Hi,

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 :

a:26:{s:3:"ns1";s:30:"dns100.internet-webhosting.com";s:3:"ns2";s:30:"dns101.internet-webhosting.com";s:3:"ns3";s:0:"";s:3:"ns4";s:0:"";s:9:"registrar";s:12:"Resellerclub";s:4:"term";s:1:"2";s:4:"cip1";s:0:"";s:4:"cip2";s:0:"";s:6:"nexus1";s:0:"";s:6:"nexus2";s:0:"";s:6:"nexus3";s:0:"";s:6:"nexus5";s:0:"";s:6:"nexus6";s:0:"";s:6:"nexus7";s:0:"";s:6:"nexus8";s:0:"";s:6:"nexus9";s:0:"";s:6:"nexus4";s:0:"";s:10:"totalprice";s:0:"";s:9:"regstatus";s:7:"Pending";s:7:"regtype";s:3:"New";s:6:"eppkey";s:0:"";s:9:"processor";s:0:"";s:5:"eauid";s:0:"";s:7:"profile";s:5:"15712";s:8:"quantity";s:1:"1";s:8:"idn_type";s:3:"eng";}

I would like to change the :

dns100.internet-webhosting.com to dns500.internet-webhosting.com

and

dns101.internet-webhosting.com to dns501.internet-webhosting.com


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

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

x
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.

GaryCommented:
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, "dns100.internet-webhosting.com to dns500.internet-webhosting.com", "new-value")

Open in new window

0
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 ?
0
GaryCommented:
Yes that will work as well.
0
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.
0

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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

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";
0
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
PHP

From novice to tech pro — start learning today.