Base table or view not found: 1051 Unknown table

In actionIndex() method of SiteController.php file I have

$marina = $command->select(‘unitlistings., images.’)

			 ->from('unitlistings ul, images imgs')


			 ->where("ul.refno = imgs.refno AND ul.district = 'Dubai Marina' AND ul.sellprice > '0' AND ul.bedrooms > '0' AND ul.status = 'available'")


			  ->limit(4)


			  ->order('rand()')


			 ->queryall();

When I load my index file I get this error: CDbCommand failed to execute the SQL statement: SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table ‘unitlistings’…

But this works fine

$marina = UnitListings::model()->findAll(array(‘condition’=>“district = ‘Dubai Marina’ AND sellprice > ‘0’ AND bedrooms > ‘0’ AND status = ‘available’”, ‘limit’ => ‘4’, ‘order’ => ‘rand()’));

Hi,

it may be uppercase/lowercase problem, somme database see the difference.

I have tried all cases UNITLISTINGS, UnitListings, Unitlistings, unitListings. But it’s still showing that error

But what is your table name in the database?

Could be that it is prefixed?

In the auto generated UnitListings.php model file there is this function

public function tableName()

{


	return 'unitlistings';


}

on the first line you wrote select(‘unitlistings.,…’) but then you gave it an alias as “ul”… so change the first line to select('ul.,…’)… same for the other table…

Ok. I fixed it. I should have been using this

$marina = $command->select(‘ul.*, imgs.*’)

->from(‘unitlistings ul, images imgs’)…

instead of

$marina = $command->select(‘unitlistings.*, images.*’)

->from(‘unitlistings ul, images imgs’)…