CategoryPHP

PHP related information

Zend Framework 1.8+ Module/Library Autoloading

Given the problems I had for the 1st Zend Framework website I did, I figured the next time I started one from scratch I would document how to get the autoloading working, since almost nowhere has it documented correctly. I forgot then too, so 3rd time lucky… The following code assumes the following: You have no model, controller or view directories at the root of application/ because they...

Testing and timing RDS/MySQL scheduled downtime with PHP

Something I was asked at work recently was “if we do this to the server, how long will it be unavailable for?” and usually the answer would be easy… however in certain circumstances you may not know. One of these is Amazon RDS, whereby you don’t really know what happens when you reboot or change the configuration of an instance, it just sort-of happens and eventually...

Google Geocoding API with PHP

If you want to know where a particular address is by latitude and longitude, but only have the normal address details like street, city, zip, country, etc. then the Google Geocoding API should be able to help. By passing it an address string it will try to work out (just like Google Maps) whereabouts the address is, and return you a JSON or XML response with what it managed to figure out. Below...

Use phpMyAdmin with a remote MySQL server

Been doing relatively proprietary work recently, so not much to share other than this little tip. If you want to use phpMyAdmin but for whatever reason the MySQL server you’re using isn’t local, you can change the host by editing line 104 in config.inc.php in the root of phpMyAdmin: $cfg['Servers'][$i]['host'] = 'localhost'; … and optionally the port if required...

Zend Framework, Zend_Db_Table ORDER BY sorting NULL as last instead of first

If you have a group of fields, some of which may be null (such as an address, in which the 1st line of the address may or may not be filled in) then you may want to sort them all so that if null appears in a field, it's sorted to the bottom of the list as opposed to the top (which is the default behaviour) $select = $table->select(); $rowset = $table->fetchAll($select...

WordPress 3.2 upgrade, WYSIWYG editor no longer loads? Now requires JSON extension

An issue I encountered recently doing a WordPress upgrade from 3.1 to 3.2, is that afterwards everything appeared to work with the exception of the editor for Posts and Pages. After working through the checklist for the manual install and checking each plugin individually, I took a look at the PHP error log and noticed that PHP didn't have the JSON extension bundled.

Access the non-direct View Helper methods in Zend Framework

Something that was temporarily puzzling me so I thought I would post about it. As in most examples to access the direct() method of a View Helper, you simply call the class name on the View Object: $view->baseUrl(); But if you want to access any of the methods other than direct() you've got to get the Helper first, as unlike most Action Helpers they don't implement a fluent interface because...

Installing PHPUnit with Zend Server (CE) on Windows using PEAR

After a few hours of trying to figure out what was failing each time, I think I've finally found the solution (which is a combination of various other tidbits of information I've picked up from other blogs) Firstly, assuming you've got a stock installation of Zend Server or Zend Server CE, it will be installed at: C:\Program Files\Zend\ZendServer\ Therefore the PEAR setup batch file will be...

Zend_Auth_Adapter_Ldap “Adapter options array not in array”

Whilst trying to setup LDAP authentication for the first time in Zend Framework, I can across this little quirk when passing parameters to Zend_Auth_Adapter_Ldap, namely that I wasn't passing an array even though it was an array (which I checked using Zend_Debug) Basically Zend Framework expects you to have multiple LDAP servers (even if you have alternative failover in place on a single...