Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $fruit_names = [];
- $stmt = $dbh->prepare('SELECT id, fruit_name FROM fruits');
- if ($stmt->execute()) {
- $result = $stmt->fetchAll();
- $result_count = count($result);
- if ($result_count > 0) {
- foreach($result as $row) {
- // decrypt and push into array
- $cur_fruit_name = $row['fruit_name'];
- try {
- $decrypted_fruit_name = Crypto::decrypt($cur_fruit_name, $user_key);
- $fruit_names[$row['id']] = $decrypted_fruit_name;
- }
- catch (Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) {
- // Either there's a bug in our code, we're trying to decrypt with the
- // wrong key, or the encrypted credit card number was corrupted in the
- // database.
- // ... handle this case ...
- $fruit_names[$row['id']] = "failed to decrypt";
- }
- }
- }
- else {
- // empty result handler
- }
- }
- // then you can search for what you originally wanted
- $requested_fruit_name = $_POST['requested_fruit']; // say apple
- $match_found = false;
- foreach ($fruit_names as $fruit_id => $fruit_name) {
- if ($fruit_name == $requested_fruit_name) {
- $match_found = true;
- return $fruit_id;
- break;
- }
- }
- if (!$match_found) {
- return 'match not found';
- }
Add Comment
Please, Sign In to add comment