views:

131

answers:

1

Hi all!

I am facing a very weird problem with mysql and doctrine [with help of codeIgniter].

I am trying to make a simple migration script taking all records from one table and after a little process, saving them to another.

However, on my laptop [running windows and wamp] I get double numbers of the original table records to have been copied to the destination table. In my colleagues' laptops, everything works fine! We are all using mysql 5.0.86 [plus windows plus wamp].

Here is the code :

 function buggy_function(){

            $this->db(); //get db connection
            $q = Doctrine_Query::create()->from('Oldtable r');
            $oldrecords = $q->fetchArray();
            $count = 0;

     foreach ($oldrecords as $oldrecord){

        $newrecord = new NewTableClass(); 
               $newrecord->password = md5($oldrecord['password']);        
        $newrecord->save();       
        echo $newrecord->id. ' Id -> saved.'      
       }     

    }

Simple as that! I have 39 records on the Old table and I am getting 78 records in the new table, which are exactly the same records, except from the unique primary key.

It seems as if the script runs twice. But the output of the script is the following :

1 Id -> saved.

2 Id -> saved.
...
...

39 Id -> saved.

Do you have any idea why this is happening? Any known bug for mysql?

Thank you in advanced!'

A: 

The only possible problem I see is in the line $oldrecords = $q->fetchArray();. I would begin there; check to make sure the $oldrecords array looks correct right before you enter the foreach loop.

eykanal