PHP PEAR DB Code Completion in Zend StudioPHP PEAR DB Code Completion in Zend Studio

Posted November 2nd, 2007 in PHP

The PEAR DB library provides a database abstraction library for PHP, along with many other useful functions for running database queries. There are a number of other database abstraction libraries for PHP, such as ADODB and ADODB Lite.

PHP editors such as Zend Studio (previously known as the Zend Development Environment), PHP Eclipse or Nusphere to name a few, have code completion built into them, so when you start typing in a function or method name, popup tips help you to know what functions are available, and what parameters need to be passed to them. I use Zend Studio for progamming in PHP, and find code completion invaluable. It saves a lot of time and makes me more efficient at programming.

When using the PEAR DB library, if you want to enable code completion for these database functions, you need to add PHPDOC syntax to the top of your function call like in the example below:

/**
 * @param DB_common $db
 */
function foo(&$db) {

The @param DB_common $db part tells Zend Studio that all references to $db in the function below are of the DB_common type. This will enable code completion for this variable, so when you type in $db-$gt; the code completion dialog will pop up with the possible method calls and available variables.

This is shown in the example screenshot below:

code completion example in zend studio

I have only tested this in Zend Studio, but the principle should be the same for other development environments which support code completed. It will also work for other database abstraction libraries; it's just a matter of working out what the class name is for the PHPDoc code block.

Related posts:

Share or Bookmark

Share or Bookmark this page using the following services. You will need to have an account with the selected service in order to post links or bookmark this page.

Subscribe or Follow

Subscribe via RSS or email, or follow me on Facebook or Twitter below. The RSS icon takes you through to Feedburner where you can select the service or application to use.

Comments

blog comments powered by Disqus