Mysql2 pdo

Quick effort to replace the old mysql php code with PDO.  This is required for ubuntu 13.10 and probably newer debian as well. 

I have mostly just quickly done the port without much thought to improving sql queries.  However PDO will allow use to use cached prepared statements and does parameter escaping and whatnot for us, hence the removal of all the quoting.  

Also this should make the PHP code at least work on postgres as well.