Right now I am doing work with PHP on a shared host with MySQL. Wasn’t my choice, of course. Maybe I can use Haskell and MySQL for this application and future ones. I’ve already tested compiling a Haskell web application on this specific hosting server, and it works fine.
This host is pretty limited. I can only use provided configuration interfaces. I had to use PHP to launch the Haskell process. Provided I can keep a process open on the server (a cron job should do it), I can probably use PHP as a kind of proxy to the FastCGI process.
The idea of using Haskell for my work sounds much more pleasant and exciting than PHP. I really wish this PHP version (5.2.6) had closures and namespaces. Yeah, it has those features now1 2, in newer versions that I can’t use, but only tacked on, when they should’ve been there from the start. Oh well.
Will post more about my Haskell-on-horrid-but-necessary-shared-hosting adventures.
On a fairly related note, MySQL with Database.HSQL.MySQL, is fairly easy. Here is a basic example, which I tried:
<- liftIO $ handleSql (return . Left . show) $
out do conn <- connect "host" "db" "username" "password"
<- query conn "SELECT * FROM blah"
statement <- collectRows getId statement
rows
closeStatement statement
disconnect connreturn $ Right rows
$ show out
output where getId :: Statement -> IO String
= flip getFieldValue "somefield" getId
This will return either (1) all the fields ‘somefield’ from table ‘blah’ or (2) an error message.
Obviously one can stick this connection in a Reader monad. There’s not really much else to check out for HSQL. I suppose that’s the point. All the work should be done in the query, anyway. Check out the rest of the documentation for more information.