简体   繁体   中英

Convert base64 encoded database

I have a database with all the data in a base64 string. What I need to do is pull every row from the database, decode it and then update it in the database.

I've written a little script but it only converts one row. How can I get it to run through all rows and convert them?

Here is what I have at the moment:

$result = mysql_query("SELECT * FROM mod_manage_testimonials") or die(mysql_error());

while($row = mysql_fetch_array($result)) {

$client_id = $row['client_id'];
$title = base64_decode($row['title']);
$content = base64_decode($row['content']);
$link = base64_decode($row['link']);

$result = mysql_query("UPDATE mod_manage_testimonials SET title='$title',content='$content',link='$link' WHERE client_id='$client_id'") 
or die(mysql_error());  

}

Don't overwrite the result $result from the SELECT -query with the return value of the the UPDATE -query

$result = mysql_query("UPDATE mod_manage_testimonials SET title='$title',content='$content',link='$link' WHERE client_id='$client_id'") or die(mysql_error());

As far as I can see $result from the UPDATE -query has no deeper meaning, so you can just omit it.

mysql_query("UPDATE mod_manage_testimonials SET title='$title',content='$content',link='$link' WHERE client_id='$client_id'") or die(mysql_error());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM