Jump to content

Recommended Posts

Hello,

Im trying to select a row in my database that has no value for a column and then the script generates a sha256 hash for it and updates that row. Sounds easy, something I would rather do by hand but with 200k+ rows its not worth my time. I have tried different things eg. put null in for (WHERE SHA256 ='') but that did not do anything, $num_rows just returns 0 all the time. I included a screenshot of my database so you an see whats going on.

 

Thanks

Joe

 

<?php
//die("This script does not work right now."); 
include ('db.php');
$con = mysql_connect($host,$username,$password);
if (!$con) 
  { 
  die('Could not connect: ' . mysql_error()); 
  } 

mysql_select_db($database, $con); 

$result = mysql_query("SELECT * FROM Main WHERE SHA256 = ''");

if(!$result)  { 
    $err=mysql_error(); 
    print $err; 
    exit(); 
} 
$num_rows = mysql_num_rows( $result ) ;
if($num_rows ==0){ 
     print "Nothing to do."; 
} else { 
echo "About to process $num_rows rows <br />\n" ;
while($row =  mysql_fetch_array($result)) 
  { 

  $id =  $row['SHA256']; 
//  echo "Deleting encid: $id <br />\n"; 
echo ("Updating $id");
$sha256 = hash('SHA256', $id);
   mysql_query("UPDATE Main SET SHA256 = '$sha256' WHERE Text = '$id' "); 
  
  } 
} 
mysql_close($con); 
?>

 

[attachment deleted by admin]

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.