Categories
- Andy and Javi: Actionscript and AIR Quick Tips
- Arc90
- Architecture
- Avi and Patrick: Java Quick Tips
- Avi: REST Quick Tips
- Ben and Matt: PHP Quick Tips
- Business
- Chris and Corey: JQuery Quick Tips
- Chris and Matt: Unix Quick Tips
- Design
- Development
- Foresight
- Javi and Joel: JQuery Quick Tips
- Javi: CF Quick Tips
- Jobs
- Joel: .Net Quick Tips
- Lab
- Music
- Patrick and Joel: XML Quick Tips
- Reviews
- Tech
- The Internets
- Thoughts
- Trends
- Web
- What We Are Reading
Archives
Category Archives:
Ben and Matt: PHP Quick Tips
Gaining Insight into Your Zend Queries
Zend Framework is great. However, there is a limitation when using the database abstraction layer: You are unable to see the SQL query Zend is generating. Below is a patch that can be applied to the Pdo.php class. It will log all SQL queries to a file. It requires that your development directory structure includes a log/directory and a sql.log file, with the correct permissions. Of course, you can change this to fit your development environment.
-- Pdo.php.bak 2008-04-21 11:04:26.000000000 -0400
+++ Pdo.php 2008-04-21 13:35:54.000000000 -0400
@@ -227,6 +227,15 @@ class Zend_Db_Statement_Pdo extends Zend
*/
public function _execute(array $params = null)
{
+ /**
+ * This does not go into production code.
+ * To use:
+ *
+ * # touch sql.log
+ * # chmod 777 sql.log
+ */
+ file_put_contents("../log/sql.log", date("D M j G:i:s T Y") . ':' . $this->_stmt->queryString . "\n", FILE_APPEND);
+
try {
if ($params !== null) {
return $this->_stmt->execute($params);
To install the patch, move to the Pdo.php directory and execute:
patch -p0 < PdoPatch.txt
Once the patch is installed, you can conveniently tail the sql.log file and watch each query.
# tail -f sql.log
It's not the most elegant hack, but it works fine for development. This is not recommended for production environments.
Permalink | Comments (3) | Technorati Tags : PHP Zend SQL Queries
Posted on March 11, 2008 by Ben SgroInserting a PDF Into MSSQL Via PHP
Ever try inserting a pdf in a MSSQL database?
Its not just a simple INSERT. In fact, you have to jump
through a number of hoops to get it to work. The included script is invoked
with a single argument, the name of the pdf. The script should be edited prior
to use so that your database credentials and field names can be set.
Once it is setup, its as easy as running the script:
chmod x+ insertPDF.php ./insertPDF.php -f fileToInsert.pdfThat's it!
Here's a link to the script:
http://www.arc90.com/_assets/insertPDF.txtPermalink | Comments (0) | Technorati Tags : pdf php sql quicktip mssql
