Property Of Non-Object Error

I have had a site hosted on a Linux box for the last year - recently we migrated the database and web app to a new provider - same setup with Linux, MySQL, Apache. I am getting a number of "Trying to get property of Non Object Errors. It always involves using findBy methods (e.g. findByPk).

The following will allow the page to resolve with no errors




<?php 

if ($contractor['trade_title'] > 0) {

     echo '<span>'.$contractor['trade_title'];

} else {

     echo '<span>'.$contractor['trade_alt'];

}                                       

?>



However if I use




<?php 

if ($contractor['trade_title'] > 0) {

    echo '<span>'.Services::model()->findByPk($contractor['trade_title'])->name;

} else {

    echo '<span>'.$contractor['trade_alt'];

}

?>



This code has not changed in a year. Yes there is a table called Services and there is a data in the $contractor array (confirmed with var_dump) - $contractor[‘trade_title’] is the primary key for the table. When I use this code on the new server that has been set up I get

Trying to get property of non-object

/var/www/html/DCompliance/protected/views/admin/smlist_contractor/index.php(265)

Line 265 is

265 echo ‘<span>’.Services::model()->findByPk($contractor[‘trade_title’])->name;

The query is formed from




$contractors = $command = Yii::app()->db->createCommand("SELECT id,

business_name,

contractor_id,

trade_title,

trade_alt,

tel,

mobile,

last_update,

email,

compliance_status, active

FROM contractors 

WHERE active = 1 AND (compliance_status != '1' && compliance_status != '8') ORDER BY last_update DESC"

)->queryAll();



The code base has not changed - only the server environment. This is driving me nuts - any help appreciated.

Anthony