Last update: 2011-07-13 12:21:19
I came across this little gotcha today:
<?php
$slash = '/';
$one = "1";
$db = new PDO('sqlite::memory:');
$db->exec('create table t("a","b")');
$db->exec('insert into t("a","b") values ("/","1")');
function fetchRequest(PDO $db, $query, array $params)
{
$stmt = $db->prepare($query);
$stmt->execute($params);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
// returns record
fetchRequest($db, 'select * from t where a = ? and b = ?', array($slash, $one));
// returns record
fetchRequest($db, 'select * from t where a = ? and b like ?', array($slash, $one));
// returns record
fetchRequest($db, 'select * from t where a = ? and b like 1', array($slash));
// returns false
fetchRequest($db, 'select * from t where a = ? and b = 1', array($slash));
I guess this has to do with binary representation of data in SQLite.