Tell me about it.
At work, I inherited some PHP application written for MySQL. My boss
wants to use PostgreSQL. "It can't be that hard to convert it," says I.
"SQL is SQL, right?"
Stop laughing back there, I'm trying to tell a story.
First off, the PHP code is littered with mysql_this() and mysql_that() and
mysql_theother(). For the most part, there are equivilent pg_this(),
pg_that() and pg_theother() calls, except that pg_this() takes a single
parameter, not the multiple parameters that pg_this() take. pg_that() has
then in reverse order, and mysql_wtf() has no direct equivilent call that I
can find.
So okay. Since I need to keep the MySQL version around, I write a bunch
of wrapper codes, wrapper_this(), wrapper_that(), wrapper_theother() and
wrapper_wtf() (which I still don't know what it does, so the PostgreSQL
version is stubbed out). So far, so good.
Until I start getting SQL errors.
"WTF?" says I. "The SQL statments are pretty much SELECT * FROM frob"
type queries. No joins. No multiple table selects, just pretty
straightforward SQL. Ah, I see ... PostgreSQL wants:
$query = "SELECT *, TO_CHAR(sent, 'Mon DD YYYY at HH12:MMam') as datesent
FROM emails WHERE listid=$listid ORDER BY sent DESC";
(Yes, I know, not valid PHP because the string constant spans the line, so
sue me 8-) instead of:
$query = "SELECT *, DATE_FORMAT(sent, '%b. %e, %Y at %l:%i%p') as datesent
FROM emails WHERE listid=$listid ORDER BY sent DESC";
Sigh. So much for keeping the differences isolated.
I'm now using git to track two separate branches (MySQL, PostgreSQL) and
as I fix one branch, import (or "cherry-pick" in git-ese) non-version
specific bug fixes into the other.
-spc (Holding back the bile on a whole bunch of PHP hate ... )