How can I update new data anyway, even if the data in the table is exactly the same?


If the new data and the data in the table are exactly the same, it does not update.
I want update even if it’s the same

How do I update in all conditions?

$query = $PDOdatabase->prepare("UPDATE kuru SET doviz=?, birim=?, tcmb=? WHERE id=? ");

Your desire to do this makes no sense. The reason that the database won’t actually write the data to the table, when the values in the query are the same as what is already in the table, is because this is a waste of resources. The database server wants to save the processing and disk access time to use for other queries.

Rather than to ask how can you do something, tell us what it is you are trying to accomplish, that leads you to believe you need to do it the stated way.

1 Like

You are really right, Forgive me!
Makes me keep the wrong job by asking how to do it

Amateurish I tried to write cron with php
I update the USD and EURO currency to the local currency i.e. exchange rates
id:1, USD => local currency
id:2, EURO => local currency
id:3, EURO = USD
I update twice every day at 10:00 and 16:00 on working days.
I update at 10:00 and set it to the next time. no problem here
However, if the exchange rates have not changed during the update process at 16:00, the update fails and cannot be adjusted to the next time.
As the update fails, it tries to update frequently and writes “Failed” logs to the database.

foreach ($rates AS $key => $value){
 $id = $value['id'];
     $doviz = $value['doviz'];
     $birim = $value['birim'];
     $tcmb = $value['tcmb'];

$query = $PDOdatabase->prepare("UPDATE kuru SET doviz=?, birim=?, tcmb=? WHERE id=? ");

      if ($query->rowCount() > 0) {
            $result = "Successful";
        } else {
            $result = "Unsuccessful";
echo $result;

From here, how can I get a “Successful” message if the current data and the recorded data are the same, ie no update is required?
On the other page, you can assume the update was successful and set it for the next time.
Or, how should do?

$query->execute([$doviz, $birim, $tcmb, $id]) will return true on success or false on failure, so you only need to check that:

$query_successful = $query->execute([$doviz, $birim, $tcmb, $id]);

if ($query_successful) {
    $result = "Successful";
} else {
    $result = "Unsuccessful";

According to the result here, the cron interprets the page
If it gets “Success” from here, the cron.php page sets the next run time and saves the log.
If it gets “Unsuccessful” result cron.php from here it won’t set up your next run. and it will run over and over again

The problem is here
If the update really fails, the cron.php should get a “Unsuccessful” message so that it tries to update again.

If the data in the database is up to date and there is no need to update it, cron.php should receive a “Successful” message.

Update failed? OR Don’t need an update?
Is it possible to make this distinction?

An update has still run successfully even if it doesn’t need to update anything. You literally just need to check the return value of $query->execute to see if your query was successful or not.

How should I do this?

I explained that in my last reply: you check the return value of $query->execute();. Which part of it did you struggle with?

Sponsor our Newsletter | Privacy Policy | Terms of Service