Yes, all tested. no way.
to reproduce it:
database:
DROP TABLE IF EXISTS `bugs`;
CREATE TABLE IF NOT EXISTS `bugs` (
`bugid` int(11) NOT NULL auto_increment,
`desc` varchar(255) NOT NULL,
`solved` tinyint(4) NOT NULL,
PRIMARY KEY (`bugid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
INSERT INTO `bugs` (`bugid`, `desc`, `solved`) VALUES
(1, 'one', 0),
(2, 'two', 0),
(3, 'three', 0),
(4, 'four', 0);
Code:
base setup of Zend
this is the code for a generic method(action) on a generic controller
(assume we have db on zend registry):
public function testAction () {
try {
$db = Zend_Registry::get('db');
$stmt = $db->query('SELECT * FROM bugs');
while ($row = $stmt->fetch()) {
echo $row['bugid'].'<br/>';
$data = array(
'solved' => 1
);
$where[] = 'bugid = '.$row['bugid'];
$db->update('bugs',$data,$where);
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
echo 'im working...';
}
after that you should see only the first record echo and update then the
loop exit and the" im working phrase" is printed!
thank you for support
:-)
Razorblade wrote:
>
>
> Have you tried to put your code in a try-catch statement?
> Have you tried print all the query that are supposed to be executed and
> run them from phpmyadmin?
> Did you get any errors?
> Maybe if you post your code we can help.
>
> Sorry for all these questions, I just want to help :)
>
>
>
> Sergio Rinaudo
>
>
>
>
>> Date: Fri, 22 May 2009 15:58:12 -0700
>> From: [email protected]
>> To: [email protected]
>> Subject: RE: [fw-general] Using fetch() in a loop, internal query doesn't
>> work
>>
>>
>> Thanks for answer,
>> what i wrote is only an example, no parse error on the code i'm testing
>> or
>> query error ;)
>> I tried all, many times, many days ago (and now to be sure..) all
>> without
>> success.
>> $db->query
>> $db->update
>> or table model, neither works, the loop exit after first cycle with no
>> errors, simply it make first update then exit from loop and the script
>> continue it's work.
>>
>> I tested it on all zend version from 1.6 to 1.8
>>
>> .....lost......
>>
>> :-((
>>
>> Razorblade wrote:
>> >
>> >
>> > I advice you to try the update method
>> >
>> > $data = array(
>> > 'solved' => 1
>> > );
>> > $where[] = "bug_id = '".$row['bug_id']."' ";
>> > $db->update($yourTableName,$data,$where);
>> >
>> > Or if you have your table model instancied
>> >
>> >
>> > $myTableModel->update($data,$where);
>> >
>> > and also, did you notice that the var $row[bug_id'] is missing a ' ?
>> >
>> > Bye
>> >
>> > Sergio Rinaudo
>> >
>> >
>> >
>> >> Date: Fri, 22 May 2009 15:09:03 -0700
>> >> From: [email protected]
>> >> To: [email protected]
>> >> Subject: Re: [fw-general] Using fetch() in a loop, internal query
>> doesn't
>> >> work
>> >>
>> >>
>> >>
>> >> chrisweb wrote:
>> >> >
>> >> >
>> >> > you could do it like this:
>> >> >
>> >> > $stmt = $db->query('SELECT * FROM bugs LIMIT 100');
>> >> >
>> >> > $rows = $stmt->fetchAll();
>> >> >
>> >> > foreach ($rows as $row) {
>> >> >
>> >> > $db->query('UPDATE bugs SET solved = 1 WHERE bug_id =
>> >> > '.$row[bug_id']);
>> >> >
>> >> > }
>> >> >
>> >> >
>> >>
>> >> Thank you for answer,
>> >> I know I can use fetchAll() method, but i have to use fetch() due the
>> >> fact
>> >> fetchAll() can be a memory killer.
>> >> If I have a large amount of data (csv export, mass mailing send and so
>> >> on) I
>> >> have to forgive fetchAll to prevent out of memory problem.
>> >> So I'm diggin to find a way to use query inside a fetch loop.....my
>> >> opinion
>> >> is that it's a big bug on zend side.
>> >> All db layer i used can do this...i can't believe that zend_db cannot
>> >> manage
>> >> this type of operations.
>> >>
>> >> maybe i should fill a bug report?
>> >>
>> >> Thank you
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Using-fetch%28%29-in-a-loop%2C-internal-query-doesn%27t-work-tp23656095p23678642.html
>> >> Sent from the Zend Framework mailing list archive at Nabble.com.
>> >>
>> >
>> > _________________________________________________________________
>> > Cerca le Parole, gioca su Typectionary!
>> > http://typectionary.it.msn.com/
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Using-fetch%28%29-in-a-loop%2C-internal-query-doesn%27t-work-tp23656095p23679133.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>>
>
> _________________________________________________________________
> Più di 30 stazioni. Ascolta la Radio su Messenger!
> http://messenger.it/radioMessenger.aspx
>
--
View this message in context:
http://www.nabble.com/Using-fetch%28%29-in-a-loop%2C-internal-query-doesn%27t-work-tp23656095p23679314.html
Sent from the Zend Framework mailing list archive at Nabble.com.