A
A
Alexander Pantyukhov2016-04-19 13:03:41
Yii
Alexander Pantyukhov, 2016-04-19 13:03:41

Why don't identical records in the database match?

There is a code for creating a message:

foreach($this->errorsArray as $error){
            $market=db\Market::findOne(['id'=>$error['marketId']]);
            $action=db\Action::findOne(['id'=>$error['actionId']]);
            $message .= "---------------  Error: Action: ".$action->name.", "."Market: ".$market->name.", Account: ".$error['login']."  ------------". "\r\n";
            $message .= "Action: ".$action->name. "\r\n";
            $message .= "Market: ".$market->name. "\r\n";
            $message .= "Account: ".$error['login']. "\r\n";
            $message .= "Date: ".$error['date']. "\r\n";
            $message .= "Message: ".$error['message']. "\r\n";
            $message .= "-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------". "\r\n";
            $message .= "\r\n";
        }

There is a code for writing to the database and sending a message:
$find= db\ErrorMessage::findOne(['date'=>$date->format('Y-m-d'),'message'=>$message]);
        if ($find==null){
            $errorMessage = new db\ErrorMessage();
            $errorMessage->date=$date->format('Y-m-d');
            $errorMessage->message=$message;
            $errorMessage->save();
            mail($to, $subject, $message, $headers);
        }

The problem is that the code runs every hour and its logic is such that it looks into the database and checks if there was such a message today or not. If not, then record a new message and send it to mail. I can't figure out why the condition ['date'=>$date->format('Ymd'),'message'=>$message] doesn't work , i.e. In a db identical records are hammered each time. I understand that most likely the problem is small, but I've been worrying about it for 2 days already. Changed everything but nothing helps. Who will tell you an approximate solution path or the solution itself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton B, 2016-04-19
@Paromon

I think the problem is in the line
which doesn't find anything. Try to start in addition to the message, save the md5 hash of messages in the database and search not by text, but by hash.

$errorMessage->message_hash=md5($message);
---
$find= db\ErrorMessage::findOne(['date'=>$date->format('Y-m-d'),'message_hash'=>md5($message]));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question