Archive for 28th mai 2008

The Space

28/05/2008  |  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.

Archives

Liens au pif

  • Frédéric de Villamil
  • Pseudocoder
  • photos de bubu
  • blogcatalog
  • Cakebaker
  • Communauté française CakePHP
  • Web Development 2
  • mes photos
  • Chez Trân
  • Formation CakePHP
  • Yahoo Pipe des sites CakePHP FR
  • pictures of the north country
  • Le blog de Pierre
  • Julien Bourgeois
  • snook.ca