Doctrine 2 + zf2 working with both SQL server and MySQL

The web application I’m working on (PHP 5.3, zf2, Doctrine2, on MySQL/Apache) has recently raised interest from the clients and it now needs to be installed on their premises, often a Windows server( arghhh!). That meant we had to make the application compatible with both MySQL and SQL-Server.
Here I summarize the changes and the solutions we adopted.
Continue reading

idbdata problem with MySQL

How to shrink/purge ibdata1 file in MySQL – Stack Overflow

That ibdata1 isn’t shrinking is a particularly annoying feature of MySQL. The ibdata1 file can´t actually be shrunk unless you delete all databases, remove the files and reload a dump. But you can configure MySQL so that each table, including its indexes, is stored as a separate file. In that way ibdata1 will not grow as large. It was a while ago I did this. However, to setup your server to use separate files for each table you need to change my.cnf in order to enable this: [mysqld] innodb_file_per_table=1

Display full query in the Exception of Zend_Db_Statement_Pdo

When working with Zend Framework 1.x and Zend_Db in particular, you might bump into an SQL problem like this

Syntax error or access violation: 
1064 You have an error in your SQL
syntax; check the manual that corresponds 
to your MySQL server version for 
the right syntax to use near ') 
ORDER BY `order` ASC' at line 1

OK, thanks a lot Zend, but what’s the query ?

the statement is kept inside $_stmt property of Zend_Db_Statement, and to display it, you need to acess the queryString property

$_stmt->queryString

Depending on the Zend version, the Zend_Db_Statement class might have a getter for it, so you can debug with

var_dump($zfDbStmt->getDriverStatement()->queryString);

You can also – of course – enable the MySQL general log and monitor the log file

[mysqld]
general_log_file = /path/to/logfile
general_log = 1