I
I
Islamfon2015-10-09 15:41:59
MySQL
Islamfon, 2015-10-09 15:41:59

How to combine 2 MYSQL (PDO) queries into 1?

$get= DB::$the->query("SELECT request FROM `statistic` WHERE `id` = '1' ");
$get= $get->fetch(PDO::FETCH_ASSOC);

DB::$the->prepare("UPDATE statistic SET request=? WHERE id=? ")->execute(array($get['request']+1, '1'));

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Mokhov, 2015-10-12
@Islamfon

in fact, the answer was already given by Sergey
, if more precisely, then apparently like this:

DB::$the->prepare('UPDATE statistic SET request = request + 1 WHERE id = ?')->execute(array(1));

S
Sergey, 2015-10-09
@Pjeroo

update statistic set request = (select request from statistic where id = 1) + 1 where id = 1;

But why? Can it be just
update statistic set request = request + 1 where id = 1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question