I have a query in PDO
which contains multiple actions. I first looked at this question to know wether or not multiple queries are even possible.
My code looks like this:
$stmt = $db->prepare(
"UPDATE
tbl_user_dashboards
SET
is_active = 0
WHERE
id_user_key_fk = 1;
INSERT INTO
tbl_user_dashboards(id_user_key_fk, dashboard_name, dashboard_description, is_active)
VALUES
(1, 'bla', 'blabla', 1);
SELECT
id_dashboard AS did,
dashboard_name AS dname,
dashboard_description AS ddesc,
is_active
FROM
tbl_user_dashboards
WHERE
id_user_key_fk = 1
ORDER BY
id_dashboard ASC;"
);
$stmt->execute();
$data = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$data[] = $row;
}
My problem is, is that the UPDATE
and INSERT
work fine, but the SELECT
doesn't work (my JSON
object stays empty and I don't get any errors, just []
as my output).
When I isolate the UPDATE
and the INSERT
and run the SELECT
as a seperate statement after the UPDATE
and INSERT
, then it does work but that's not my preferable solution.
Any thoughts on this?