a php developer weblog

blog Closed!
calin view of the web development world

2006/3/23

PEAR affectedRows() problem

Tags:
@ 07:55 AM (26 months, 6 days ago)
In case you also use PEAR::DB and share my taste in writing explicit multiple line queries like this:

$query = "
/* "
. __FUNCTION__ ." $this->context */
UPDATE
    $this
->tbl_ic_cdrs ic,
    ...
SET
    ...
WHERE  
    ...
"
;

 
...then you know already that this makes the SQL easy to read, nice formatted, easy to debug etc. Unfortunatelly this breaks the PEAR $db->affectedRows() that returns always 0. To fix this, you need to put the REPLACE/INSERT word immediately after the double quote:

$query = "UPDATE
/* "
. __FUNCTION__ ." $this->context */
    $this
->tbl_ic_cdrs ic,
    ...
SET
    ...
WHERE  
    ...
"
;

or simply drop the comment and:

$query=trim($query);

(reason for this problem is the preg_match in DB::isManip()). I subscribed this to php.net/mysql_affected_rows but got rejected, probably because it relates to PEAR::DB more.