My task today was to make Rob Allen’s Zend framework tutorial project run on Windows. Some years ago such task could have been a problem, but as you will see, now it’s nothing special.
To start with, Windows sometimes really annoys. For example, by default I can’t add files to C:\inetpub\wwwroot. It doesn’t ask for “Allow/Cancel?“, is doesn’t show permissions error – you just can’t do anything. I decided not to waste my time trying to find a way how to do it and ended up with virtual directory pointed to my project folder. I’m using Windows 7, so one can run programs as administrator, but having two Explorers is not a very good idea, especially when you can’t tell a difference between admin and non-admin mode (can you?).
First problem was routes – almost all frameworks nowadays uses something like “/controller/action/id” which is achieved by mod_rewrite and .htaccess. However, IIS is not Apache, hence .htaccess doesn’t exist. Although IIS has a routing module which pretty much works the same and also has nice a GUI for all who doesn’t know how to use regexp’s. Furthermore, it also has import function which surprisingly imports from .htaccess – select file, click Import, remove or fix not recognized rules and click Apply. I haven’t tried any complex rules, but since most of frameworks only require to redirect everything (“^.*$”) it should work.
Next “problem” is the database. MySQL works fine in Windows, but I wanted to use MSSQL. Not only because I haven’t tried MSSQL before, but also because MSSQL is much more integrated into Windows. However, MSSQL driver in PHP has some limitations. Nevertheless, Microsoft has released a native driver, which seems to have fixed all previous problems. You only need to download actual driver from here and PHP extensions from here. Extension can be used like this (it provides sqlsrv_* functions), however I really prefer using PDO or other object oriented database layer. That’s why I use it like this:
try { $hostname = "localhost\SQLEXPRESS"; //host $dbname = "zf-tutorial"; //db name $username = "sa"; // username like 'sa' $pw = "juozas"; // password for the user $dsn = "Driver={SQL Server Native Client 10.0}; Server={$hostname}; Database={$dbname}; Uid={$username}; Pwd={$pw};"; $dbh = new PDO ("odbc:" . $dsn); } catch (PDOException $e) { echo "Failed to get DB handle: " . $e->getMessage() . PHP_EOL; exit; } $sth = $dbh->prepare("SELECT * FROM albums"); $sth->execute(); $result = $sth->fetchAll(); print_r($result);
I should add, that I haven’t tested it much, but at least demo project from the tutorial works. Later this week I will probably choose which method to use (sqlsrv_* or PDO), because Zend framework currently doesn’t support MSSQL Native client and I will implement adapter myself (Zend_Db_Adapters are around 500 lines). Rob Allen is also working on a driver implementation for Zend so one of us should come with a solution pretty soon. Currently I’m using Zend_Db_Adapter_Pdo_Odbc from here, however it still works only as a hack.
That’s all – your Zend Framework project should work (you may also need to set correct file permissions).
If I wouldn’t have started Winphp competition, I may have never realized how Microsoft is struggling to support PHP. Starting from blogs and ending with special drivers, tutorials and even competitions. Is Microsoft trying to “repair” its public profile?







