FaaPz / PDO

Just another PDO database library
MIT License
316 stars 103 forks source link

MD5 of column value in where clause #136

Closed mridah closed 3 years ago

mridah commented 4 years ago

suppose I have a table like this:

------ mytable-----
id  |   col1  |   col2   |   col3

I want to write the following statement in PDO:

select * from mytable where md5('some-salt' + id) = 'value-to-compare-to';

Is this possible ? @FaaPz @kwhat @bmutinda

kwhat commented 3 years ago
$value = 'value-to-compare-to';
$database->select()
                 ->from('mytable')
                 ->where(new Conditional('md5("some-salt" + id)', '=', $value))
                 ->execute();

OR

$database->select()
                 ->from('mytable')
                 ->where(new Conditional('md5("some-salt" + id)', '=', new Raw('value-to-compare-to')))
                 ->execute();