How to update new tables inside another update request?

I have a legacy system and I have a php file inside it updating one table. Now I have added a new table to my db and I want to update this table. The problem is that (for some reason) I cannot use another request, and I need to change the current request.

simplified old request: $q = "UPDATE t1 SET var=$var WHERE id=1";

I can’t use "UPDATE t1,t2 SET t1.var=$var t2.var=$var2 WHERE id=1"as it adds too much processing time. Can I run two update requests in a single request? I use commands mysqlthroughout my system and I cannot change it to mysqli.

+4
source share
1 answer

2 .: -)

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {die("Connection failed: " . $conn->connect_error);}

$sql = "UPDATE t1 SET var=$var WHERE id=1";
$sql2 = "UPDATE t2 SET var=$var WHERE id=1";

if ($conn->query($sql) === TRUE) {
    echo "t1 updated successfully";
} else {
    echo "Error updating t1: " . $conn->error;
}

if ($conn->query($sql2) === TRUE) {
    echo "t2 updated successfully";
} else {
    echo "Error updating t2: " . $conn->error;
}

$conn->close();
?>
0

Source: https://habr.com/ru/post/1652049/


All Articles