In a recent post to his blog Johannes Schluter looks at how you can use the new experimental MySQL driver for PHP, mysqlnd, and get into the streams that connect PHP and your MySQL database connections.
Ever wondered what your PHP application and MySQL actually do? An experimental mysqlnd branch will give you full access to the network communication stream. Using a custom PHP stream filter you can then intercept the communication.
He shows how to attach a filter on to the stream and what sort of output it would give for a query that wasn't valid SQL (including all of the "behind the scenes" queries that the database does to get table information from the schema).