Hi,

I have a table in my database with name `pro`. One of the fields stores encrypted values. In this case, 'id'.
When I run print_r($record); or print_r($temp); I got an Object array. How is it possible to decrypt this Object in order to obtain the encrypted value?

Inserting values


global $user;
$urname = $user ->name;
$id = "a1";
$idEncrypt = encrypt($id);

$nid = db_insert('pro') // Table name no longer needs {}
->fields(array('nameuser', 'id'))
->values(array(
  'nameuser' => $urname,
  'id' => $idEncrypt
))
->execute();

Getting values

try{
$query = db_select('pro', 'c');
$query->condition('c.nameuser', 'peter', '=');
$query->fields('c',array('id'));
$result = $query->execute();
$temp = array();
  foreach ($result as $record) {
          array_push($temp, $record);
  }
   foreach ($temp as $v){
   $testdecrypt = decrypt($v);
   echo $testdecrypt;
   }
}
catch (PDOException $e) {
  drupal_set_message(t('Error: %message', array('%message' => $e->getMessage())), 'error');
}

Comments

rlhawk’s picture

Status: Active » Fixed

You've probably already figured this out, but executing a query with db_select will return a SelectQuery object, so that's what you're seeing. In order to process the results, you'll need to use fetchAssoc(), or a similar method. That's just basic Drupal DB stuff, not specific to Encrypt.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.