0

I found this code on a legacy app:

$salt = $this->generateSalt();
$new_pass_update = Doctrine_Query::create()
  ->update('User')
  ->set('password', '"'. $this->hash($newPass, $salt) .'"')
  ->set('salt', "sleep(10)")    // $salt)  <- I replaced this
  ->where('email = ?', array($mail))
  ->getDql();                
die($new_pass_update);

I was shocked to see this Dql generated as output:

UPDATE User SET password = "3dbe00a167653a1aaee01d93e77e730e" 
salt = sleep(10) WHERE email = ?

First of all, I didn't expect to see the quotation marks around the password value. I thougt that Doctrine would do that for me, so I tried the second argument without them, but I was shocked to see this Dql generated as output:

UPDATE User SET password = "3dbe00a167653a1aaee01d93e77e730e" 
salt = sleep(10) WHERE email = ?

If I change ->getDql() for -> execute() that's exactly the query that is executed and the db sleeps for 10 seconds.

Why is doctrine behaving like this?

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Sebastián Grignoli
  • 32,444
  • 17
  • 71
  • 86

1 Answers1

1

As Gumbo pointed out, the right API to use with Doctrine 1.* update syntax is:

$new_pass_update = Doctrine_Query::create()
  ->update('User')
  ->set('password', "?", $this->hash($newPass, $salt))
  ->set('salt', "?", $salt)
  ->where('email = ?', array($mail))
  ->execute();

so, the second argument should be "?" and the third one, the associated value.

Sebastián Grignoli
  • 32,444
  • 17
  • 71
  • 86