Duplicate records in mysql for insertion using doctrine

I am facing a very strange problem with mysql and doctrine [using codeIgniter].

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

However, on my laptop [windows launch and wamp] I am getting duplicate numbers of the original table entries that were copied to the destination table. Everything works fine in my colleagues' laptops! 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.'      
       }     

    }

      

Just! I have 39 records in the Old table and I get 78 records in the new table, which are exactly the same records except for the unique primary key.

It seems like the script is being executed twice. But the script's output is as follows:

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 for your help!

+2


a source to share


1 answer


The only possible problem I see is in the line $oldrecords = $q->fetchArray();

. I would start there; make sure the array $oldrecords

looks correct before entering the loop foreach

.



0


a source







All Articles