Jump to content

[PHP + MYSQL] Selecting rows where column is blank


3dhomejoe

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.