11 Aug 2015 | 2 min. (290 words)

Cakephp 2.6.7  rawQuery bug

Small observation i had with cakephp 2.6.7 .

I was trying to write a query with cakephp and  noticed that the query was not

being sent to the server for processing .

I was using the rawQuery method and not the orm  methods like find etc...

Query is

$query=" SELECT id,stock_available FROM products WHERE  (id = ? and stock_available >= ?)or   (id  = ? and stock_available >= ?) FOR UPDATE";
$query_params=array(1,50,2,30);
$response = $this->Product->getDataSource()->rawQuery($query,$query_params);

It was because the  rawQuery method  was missing an extra option which was

preventing the query from being run  due  to  confusion in this section

      return $this->execute($sql, $params);                   

This was accepting two parameters instead of three and due to this was

mistaking the $params value for the options value thus query was not run .

query was being run as

public function rawQuery($sql, $params = array()) {                        
      $this->took = $this->numRows = false;                                    
      return $this->execute($sql, $params);                    
      }

Instead of

public function rawQuery($sql, $params = array()) {                        
      $this->took = $this->numRows = false;                                    
      return $this->execute($sql, array(), $params);                   
      }

It has subsequently been fixed .

Issue is at this link .

php cakephp
Twitter Facebook Google+

Pagination using backbone.js and underscore template

…

Theme Bleak by zutrinken Published with Hugo
Menu