I am using laravel v6.X als php 7.2 in my project. I have a database which some users update during the day when they are at work. And I built a management system for this data. To do this I had to insert the data from db1 (which users constantly add data) to a db2, I used laravel and query to insert the db2 with the help of a cronJob which runs every 60 seconds. My problem is that when the data is inserted in db2 some fields come empty but in reality these fields in db1 are filled, (this happens 10-15 times a day that users work around 9 hours, there are cases it happens even less about 3 times a day to add such records to db 2.)
NOTE: I check the data in db1 and db2 via student_id that both tables have the same
cronjob funtion for executing every 1 minute
$data = DB::connection('mysql2') ->table('students') ->where('status', '=', 'Y') ->get();
foreach($data as $key => $aStudent){
// Check if student_id dublicated
$existing_data_in = DB::table('student')->where("student_id", $aStudent->student_id)->first();
if ( ! $existing_data_in) {
DB::connection('mysql')->table('student')->updateOrInsert([ // i use update or insert now
"first_name" =>$aStudent->first_name,
"last_name" =>$aStudent->last_name,
"age" =>$aStudent->age,
"student_id" =>$aStudent->student_id,
"created_at" =>$aStudent->created_at
]);
}
}
Log::info('Success, Data Updated');
Some logs for this case what i get when query execudet as i describe above
[2022-01-19 14:16:17] local.INFO: select `student_id` `first_name`, `last_name`, `age`, `created_at` from `students` where `student_id` = ? limit 1 [421]
// this comes from query where i check for dublicated lines i think
[2022-01-19 14:16:17] local.INFO: select * from `student` where `student_id` = ? limit 1 [421]
[2022-01-19 14:16:17] local.INFO: insert into `student`
(`student_id`, `first_name`, `last_name`, `age`, `created_at`) values
(?, ?, ?, ?, ?)
["421","name","","38","2022-01-19 14:13:35"]