This is the code that I'm using to try comparing to a VARBINARY
using PHP PDO:
$st = $pdo->prepare('SELECT * FROM `xf_ip` WHERE user_id = ? AND ip = ?;');
$st ->execute(array($new_row[':forums_id'], $hexip));
I tried prefacing it with 0x
('0x' . $hexip
), as well as using bindParam
:
$st = $pdo->prepare('SELECT * FROM `xf_ip` WHERE user_id = :user_id AND ip = :ip;');
$st->bindParam(':user_id', $new_row[':forums_id'], \PDO::PARAM_INT);
$st->bindParam(':ip', $hexip, \PDO::PARAM_LOB);
$st->execute();
This is the only query that works, but it's an unsafe query because it's not prepared and could be vulnerable to SQL injection:
$st = $pdo->query('SELECT * FROM `xf_ip` WHERE user_id = ' . (int) $new_row[':forums_id'] . ' AND ip = 0x' . $hexip);
The hexip has to be in the format 0xFFFFFFFF
with no quotes, and not in integer format, otherwise MySQL will not accept it.
Is this not possible with PDO?