Duplicate entries on mysql on insert using doctrine

Posted by Nikos Galis on Stack Overflow See other posts from Stack Overflow or by Nikos Galis
Published on 2010-05-14T16:17:41Z Indexed on 2010/05/14 16:24 UTC
Read the original article Hit count: 421

Filed under:
|
|
|

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!'

© Stack Overflow or respective owner

Related posts about mysql

Related posts about doctrine