Error when clicking on tag

Whenever we click on a tag on a page we get an error message on screen saying an exception has occurred. In the application logs I see the messages below. It appears to be some sort of error in the sql statement according to the message. We are running on a RHEL 5 system fully patched out which uses php-5.1.6-20.el5_2.1. I know the requirements are to have PHP 5.2 but this needs to run on a Red Hat system and if I upgrade PHP I'm no longer supported so thats just not an option at this point. Any ideas?

Type: Omeka_Db_Exception
Date: 2008-09-30T12:53:20-0400
An error occurred within the following SQL statement:

FROM omeka_items i
i.public = 1
AND IN (Object id #137)

^MStack Trace:
#0 /var/www/hosts/memories/html/lits/application/libraries/Zend/Db/Statement.php(109): Zend_Db_Statement_Mysqli->_prepare('SELECT??COUNT(D...')
#1 /var/www/hosts/memories/html/lits/application/libraries/Zend/Db/Adapter/Mysqli.php(284): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), 'SELECT??COUNT(D...')
#2 /var/www/hosts/memories/html/lits/application/libraries/Zend/Db/Adapter/Abstract.php(261): Zend_Db_Adapter_Mysqli->prepare('SELECT??COUNT(D...')
#3 /var/www/hosts/memories/html/lits/application/libraries/Omeka/Db.php(260): Zend_Db_Adapter_Abstract->query('SELECT??COUNT(D...', Array)
#4 /var/www/hosts/memories/html/lits/application/libraries/Omeka/Db.php(280): Omeka_Db->query(Object(Omeka_Select), Array)
#5 /var/www/hosts/memories/html/lits/application/models/ItemTable.php(377): Omeka_Db->fetchOne(Object(Omeka_Select))
#6 /var/www/hosts/memories/html/lits/application/controllers/ItemsController.php(161): ItemTable->findBy(Array, true)
#7 /var/www/hosts/memories/html/lits/application/libraries/Zend/Controller/Action.php(497): ItemsController->browseAction()
#8 /var/www/hosts/memories/html/lits/application/libraries/Zend/Controller/Dispatcher/Standard.php(237): Zend_Controller_Action->dispatch('browseAction')
#9 /var/www/hosts/memories/html/lits/application/libraries/Zend/Controller/Front.php(911): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#10 /var/www/hosts/memories/html/lits/application/libraries/Omeka/Core.php(317): Zend_Controller_Front->dispatch()
#11 /var/www/hosts/memories/html/lits/index.php(15): Omeka_Core->dispatch()
#12 {main}

Are you using the most-current version of Omeka, 0.9.2?

Dave, as I mentioned we are running RHEL 5.2 which doesn't support php 5.2 yet so when you try to even install omeka 0.9.2 it won't go any further. Any ideas on the error above? This error would indicate its more of a sql syntax error than a php problem.

The problem with the SQL statement is related to the way that PHP 5.1 casts objects to strings. You see the part where it says "Object id #137" in the SQL statement; that is the incorrect representation of an object as a string, whereas it should be another SQL statement that is nested in that IN ( ) clause.

One of the big differences between PHP 5.1 and 5.2 is the way that objects are converted to strings, which in this case is causing it to nosedive.

In this case, the offending code in question is on line 320 (or thereabouts, depending on the version you're running) of application/models/ItemTable.php, and it is this line:

$select->where(' IN (' . (string) $subSelect . ')');

if you change (string) $subSelect to $subSelect->__toString() it will probably work. There may be a bunch of cases like this unfortunately, so there could be multiple spots where your Omeka installation bombs out.

What version of the software are you running?

We are running version 0.9.0 of the software. I just tried upgrading to 0.9.2 and got it to work but we are still having the same issues with tags. So are the only options in this case to run Omeka to either go through and fix the code or break my support with Red Hat? Sounds like a bummer either way. Thanks for the help thus far!

Some of our other users have had luck running Omeka on a virtual machine, which would give you the most control over how your system is configured. Unfortunately we don't have the resources to continuously test and design against multiple versions of PHP, but if you have any luck getting it to work on your server, please send us a patch and we'll see about integrating it into the Omeka codebase. Thanks!

Kris, with your suggestions this is now working just fine so far. We are still running the 0.9.0 version of Omeka, but everything is working nice and stably so far. We are running everything on RHEL 5.2 with their PHP

I made the changes to the string casting in the following files:

Once I made the changes to those files as you directed above we are able to search and order by tag with no errors at all.

I'm hoping Red Hat will move PHP to version 5.2 in their upcoming update 3 to RHEL server but there is no guarantee of that and it wouldn't surprise me if they didn't but we can always hope. The bummer is that they have PHP 5.2 available in their application stack product which includes JBOSS and an updated LAMP stack among other things, but application stack is prohibitively expensive unless you are actually need the JBOSS portion of things.

If others want to make the plunge and upgrade their RHEL servers to PHP 5.2 there are third party packages out there I found in doing my research. Obviously, using these packages takes you out of having a supported PHP install from Red Hat's perspective but that may not be a big deal to some people. At any rate I found the packages listed below for anyone thats interested. I didn't actually try them myself so use at your own risk, but I imagine they work well.