Getting Symfony 1.4 to Run on a Windows Server Running PHP >= 5.3

If you’re running a LAMP environment, you might wonder what’s the big deal, it should just work right? No. When PHP upgraded from the 5.2 series to the 5.3 series, it dropped its support for the MSSQL driver (php_mssql.dll) and was not going to continue support. You had to use Microsofts SQLSRV driver ( Well that’s ok, you could use the PDO_DBLIB… nope, PHP quit supporting that on all Windows servers running PHP >= 5.3. ( *fudge*

Ok, so now we have the SQLSRV driver from Microsoft, sweet. No… wait… Symfony 1.4 uses a Doctrine version that has no idea what SQLSRV is! *sigh* Hmm, maybe we can use the PDO_SQLSRV that Microsoft developed? Well, that should work (and actually does) except the older Doctrine version is not aware of pdo_sqlsrv’s existence. So lets make it aware!

Making Symfony 1.4 PDO_SQLSRV aware

Before you being, please make sure you have the following installed:

PDO SQL Drivers:

SQL Server 2012 Client:

First we need to create the PDO_Sqlsrv class. I’ll I did was copy the existing Doctrine_Connection_Mssql class and renamed it to Doctrine_Connection_Sqlsrv. You can do this because there is nothing special about the SQL code, it’s all just handled by the DLL. Doctrine just needs a class to run.

Once you’ve done that, you need to tell Doctrine_Manager about your new connection driver. Go to line 82 and add your new class to the $_connectionDrivers array:

protected $_connectionDrivers = array(
'db2' => 'Doctrine_Connection_Db2',
'mysql' => 'Doctrine_Connection_Mysql',
'mysqli' => 'Doctrine_Connection_Mysql',
'sqlite' => 'Doctrine_Connection_Sqlite',
'pgsql' => 'Doctrine_Connection_Pgsql',
'oci' => 'Doctrine_Connection_Oracle',
'oci8' => 'Doctrine_Connection_Oracle',
'oracle' => 'Doctrine_Connection_Oracle',
'mssql' => 'Doctrine_Connection_Mssql',
'dblib' => 'Doctrine_Connection_Mssql',
'odbc' => 'Doctrine_Connection_Mssql',
'sqlsrv' => 'Doctrine_Connection_Sqlsrv',
'mock' => 'Doctrine_Connection_Mock'

Finally, tell Doctrine to use Sqlsrv (config_databases.yaml)

return array(
'doctrine' => new sfDoctrineDatabase(array (
'dsn' => 'sqlsrv:server=my.db.server;Database=my_db',
'username' => $username,
'password' => $password,
'name' => 'doctrine',

Wala, Symfony 1.4 should now be running on your Windows Server running PHP 5.3 and 5.4.

Converting an MS Word Document to a PDF With PHP and COM

Usually I post about stuff that I just figured out, but this isn’t the case this time. I just needed to make a filename update to an existing application that generates Word Documents (well really RTF documents) and then converts them to PDFs and thought that the topic was interesting enough to post about.

I’m not going to explain how I create my RTF docment. (Read over one of the downloads on this link if you really want to know how to code pure RTF documents: I’m just going to show you how to convert the document to a PDF. (Quite simple actually)
So to use COM (Component Object Model) to convert MS Word Documents to PDF, you need to do three things:

1) Install PHP, MS Word and Adobe onto your IIS Server.
2) Configure the MS Word component service on the server.
3) Code!

Install PHP and MS Word onto your IIS Server
Configure the MS Word component service on the server (IIS 6.0)
1) Go to Start->Administrative Tools->Component Services

2) Click on Component Services and then Computers->My Computer->DCOM Config
3) Find the MS Word package, right click->properties
4) Under the Location tab, make sure that only “Run application on this computer” is checked.
5) Under the Security tab, give the Internet User access to “Launch and Activation Permissions” and “Access Permission”.
6) Under the Identity tab, specify the user that will run Word.


First launch Word:

$word = new COM('word.application') or die('Unable to load Word');
$word->Visible = 1;
$word->DisplayAlerts = 0;

Create a new pdf:

// Open an existing document
$doc = $word->Documents->Open('file.doc');

// Create PDF.
$doc->ExportAsFixedFormat('/web/public/file.pdf', 17, false, 0, 0, 0, 0, 7, true, true, 2, true, true, false);

Refer to the MSDN docs to see what all the arguments are:

Display to user:

header("Content-Disposition: inline; filename=file.pdf");
header("Content-type: application/x-pdf");
header("Location: /file.pdf");

With COM you can basically get access to most MS applications, so it’s kind of like being able to program using the .NET Framework, except you’ll have a smaller API and more overhead (my assumption).

To learn more about COM refer to