4

I am trying to update a record with the DBAL Query builder and it does not seem to be working. The data column that I am trying to set will only work if I replace the test example value I have here with a number.

In that case it will update my record perfectly fine.

Even if I use setParameter for it as well it will silently fail.

$queryBuilder = $this->connection
                ->update($this->table)
                ->where('id = ?')
                ->set('data', 'test')
                ->setParameter(0, $sessionId);

Am I mis-using this or is something else going on?

Edit:

The insert statement works perfectly fine:

$queryBuilder = $this->connection
                ->insert($this->table)
                ->values([
                    'id' => '?',
                    'secure' => '?',
                    'modified' => '?',
                    'lifetime' => '?',
                    'user_hash' => '?',
                    'data' => '?',
                ])
                ->setParameter(0, $sessionId)
                ->setParameter(1, 'y')
                ->setParameter(2, time())
                ->setParameter(3, $this->minutes)
                ->setParameter(4, 'test')
                ->setParameter(5, $data);
        }
Stephan-v
  • 19,255
  • 31
  • 115
  • 201

1 Answers1

3

You can use parameters in update the same way you use it in insert:

$queryBuilder = $this->connection
            ->update($this->table)
            ->set('data', '?')
            ->where('id = ?')
            ->setParameter(0, 'test')
            ->setParameter(1, $sessionId);
Alex Blex
  • 34,704
  • 7
  • 48
  • 75
  • You swapped the `set` and `where`. I tried it and it works now, guess this is pretty important. You also can absolutely not swap the `setParameters` even if you update their corresponding number correctly. Guess you are my guardian angel today. Thanks for helping out(again lol). – Stephan-v Jan 25 '17 at 14:57
  • I see no reason why it shouldn't. Are you saying `->set('data', ':data')->setParameter('data', 'test')` isn't working? – Alex Blex Jan 25 '17 at 15:18
  • You are not mixing positional and named parameters, are you? – Alex Blex Jan 25 '17 at 15:18
  • Deleted the comment. Figured it out now. Thanks for helping. – Stephan-v Jan 25 '17 at 15:23