views:

217

answers:

2

I asked this question on the CakePHP google-group but didn't find any resolution, so hopefully will have better luck here.

I've been developing on CakePHP for a bit and decided to have a localhost version on MAMP so that I could demo my app to people without being dependent on an Internet connection.

We have a couple of complex MySQL queries being made, and using

$this->query('SELECT...');

We've placed these in the appropriate models within a function to remove all this logic from the controller. Hence from the Controller we'll have something like

$this->Users->getMeSomething($variable);

, that goes to the user.php model and runs that function. This works fine on our live and dev sites, but for some reason on MAMP I'm getting an error whenever this type of call is made, as an example of one of the calls:

Error:

Warning (512): SQL Error: 1064: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the
right syntax to use near '__getUsersForUsers' at line 1 [CORE/cake/
libs/model/datasources/dbo_source.php, line 525]

Context:

DboSource::showQuery() - CORE/cake/libs/model/datasources/
dbo_source.php, line 525
DboSource::execute() - CORE/cake/libs/model/datasources/
dbo_source.php, line 201
DboSource::fetchAll() - CORE/cake/libs/model/datasources/
dbo_source.php, line 336
DboSource::query() - CORE/cake/libs/model/datasources/dbo_source.php,
line 297
Model::call__() - CORE/cake/libs/model/model.php, line 441
Overloadable::__call() - CORE/cake/libs/overloadable_php5.php, line 52
AppModel::__getUsersForUsers() - [internal], line ??
UsersController::view() - APP/controllers/users_controller.php, line
401
Object::dispatchMethod() - CORE/cake/libs/object.php, line 118
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 227
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 194
[main] - APP/webroot/index.php, line 88

Line 88 on webroot is this: $Dispatcher->dispatch($url);

I've tried both 1.2 and 1.2.5 of CakePHP. MySQL on MAMP is 5.1.31 and on my host, MediaTemple, is 5.1.26-rc

Thanks for any help

A: 

What happens if you force cake to echo the query, and you try to run it manually in a mySQL client? It looks like your local version is creating a different query than the version on your host -- since mySQL is complaining about syntax.

timdev
The query inside the function itself is fine. For some reason Cake is interpreting the model function as a MySQL function
828
A: 

Found a solution. It has nothing to do with MAMP, in fact we found this bug on our dev server eventually, but not our live server.

Basically, the Cake core's were different on both servers - but minutely so (one was RC, the other was the final). The older one was able to interpret the HABTM model relationship, but the newer core's don't unless you explicitly specify them (this must be a bug since I followed all the naming conventions).

So here's how it will work: - you have a model user.php and tag.php - In user.php, you will have a HABTM relationship with the Tag model - In that array, add the field: 'with' => 'UsersTag' - Do the same for tag.php

This way CakePHP doesn't have to figure out what the model name is (although it should be able to)

828