PDO/SQLite gotcha
7 août 2010 16:12:22
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.
PHP scrobbler takeover
30 juil. 2010 12:20:17
BenXo take over the PHP scrobbler class. And that's from a LastFM employee ! :-)
Access Control List for ReadBean / Shozu
29 juil. 2010 09:41:23
I've implemented a simple ACL system for Shozu on top of RedBean (using the ActiveBean layer). Get it here.
Some hints:
// create new user identified by email with password php boot.php acl/cli/adduser/useremail@domain.com/userpassword // change user password php boot.php acl/cli/setpassword/useremail@domain.com/userpassword //give admin, developer and customer roles to user (create those if needed) php boot.php acl/cli/addroles/useremail@domain.com/admin,developer,customer // remove roles from user php boot.php acl/cli/removeroles/useremail@domain.com/admin,developer // list all roles php boot.php acl/cli/listroles // list all roles for given user php boot.php acl/cli/listroles/useremail@domain.com // list all users php boot.php acl/cli/listusers // list all users matching the pattern php boot.php acl/cli/listusers/%john% // give admin, backup, copy, whatever resources to admin role php boot.php acl/cli/addresources/admin/admin,backup,copy,whatever // remove resources php boot.php acl/cli/removeresources/admin/backup // list all resources php boot.php acl/cli/listresources // list all resources associated with given role php boot.php acl/cli/listresources/admin