I would like to do these actions step by step:
- first DB update
- copy file
- unlink file
- second DB update
It is working, but I don't know if my code is correct/valid:
$update1 = $DB->query("UPDATE...");
if ($update1)
{
if (copy("..."))
{
if (unlink("..."))
{
$update2 = $DB->query("UPDATE ...");
}
}
}
Is it possible to use if statement this way?
I found that it is usually used with PHP operators and PHP MySQL select, for example:
$select = $DB->row("SELECT number...");
if ($select->number == 2) {
...
}
ifis used pretty much whenever there is conditional branching that needs to occur. It doesn't matter where the value comes from (and yes, SQL is one popular data source). In any case, see the documentation for whichever method to see what the results mean. You may also want to ensure that update2 "succeeded" and/or use a transaction or optimistic concurrency.