Select random row using PDO
This query will return a random id from the DB with one simple SQL statement instead of using PHPs built in rand function. 

MySQL:

$pdo-&gt;query('SELECT id FROM xxxxx ORDER BY RAND() LIMIT 1');


MS SQL:

$pdo-&gt;query('SELECT id FROM xxxxxx order by NEWID()');


I'm not entirely sure what database you're using, but this would eliminate a few lines of code. 

Also, I'm not sure if you're using a database class to wrap around PHPs PDO class but I generally build an array and store my bound parameters in it then execute it. Looks a little neater.