The Space

28/05/2008, 14:29  |  Tags:  |  Publié dans cakephp, tips

Last week-end, I came accross a tiny but annoying problem.

I had this simple line of code :

$artist = $this->Artist->find(array(’name’ => $name);

Most of the times, it worked fine. But sometimes I had to search for “!!!” or “In Scary Stereo” and CakePHP threw an error, saying the SQL query was wrong. And it was, because CakePHP automagically transformed the “!” and the “In” into SQL operators…
I first thought that I need to force the “equal” operator, like this:

$artist = $this->Artist->find(array(’name’ => ‘=’. $name);

Then someone on CakePHP’s google group gave me that tip :

$artist = $this->Artist->find(array(’name’ => ‘!-’.$name);

It didn’t work. But Grant Cox suggested me to add as simple space after the equal sign:

$artist = $this->Artist->find(array(’name’ => ‘= ‘. $name);

That worked!!

Too much magic kills the magic…

[edit]
La RC1 change quelque peu tout cela : l’opérateur passe à gauche de la flèche, et c’est bien mieux ainsi. En revanche, j’ai un gros soucis de connexion à deux bases de données différentes avec cette nouvelle version.

Si vous avez apprécié cet article, abonnez-vous au fil rss de ce blog pour ne pas louper les prochains.

Leave a Response

Archives

Liens au pif

  • Communauté française CakePHP
  • POPnews
  • Mark Story
  • Google Group CakePHP Fr
  • Debuggable
  • Formation CakePHP
  • Cakebaker
  • photos de bubu
  • Julien Bourgeois
  • blogcatalog
  • pictures of the north country
  • Pseudocoder
  • Le blog de Pierre
  • Yahoo Pipe des sites CakePHP FR
  • Web Development 2