MySQL query from PHP script not inserting new records -
i have php script built off of mysql query reads 1 database , inserts , should update on duplicate keys.
i completed other day, ran in powershell throughout day , did initial insert , updated appropriately throughout. got work today, ran in powershell , got successful connection message in powershell, no errors, database table did not insert new records today.
for comparison, query run in workbench on test version of table inserting new records every day , updating throughout well.
without errors, can't tell why script not inserting new records today.
i'll post resources below, details, table structure same (id ai primary key, unique index on extension , date_of_report)
here script:
$servername = ""; $username = ""; $password = ""; $servername2 = ""; $username2 = ""; $password2 = "*"; // create connection $conn = new mysqli($servername, $username, $password); $conn2 = new mysqli($servername2, $username2, $password2); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } echo "connected successfully"; // check connection2 if ($conn2->connect_error) { die("connection failed: " . $conn2->connect_error); } echo "connected successfully"; $data = mysqli_query($conn, "select c.extension , responsibleuserextensionid , sum(duration) total_talk_time_seconds , round(sum(duration) / 60,2) total_talk_time_minutes , sum(if(legtype1 = 1,1,0)) total_outbound , sum(if(legtype1 = 2,1,0)) total_inbound , sum(if(answered = 1,0,1)) total_missed , sum(if(legtype1 = 1,1,0)) + sum(if(legtype1 = 2,1,0)) total_calls , now() time_of_report , curdate() date_of_report cdrdb.session inner join cdrdb.callsummary b on a.notablecallid = b.notablecallid inner join cdrdb.mxuser c on a.responsibleuserextensionid = c.extensionid b.ts >= curdate() , c.extension in (7295, 7306, 7218, 7247, 7330, 7000, 7358) group c.extension"); $stmt = mysqli_prepare($conn2, "insert jfi.ambitionphone(extension, extid, total_talk_time_seconds, total_talk_time_minutes,total_outbound, total_inbound, missed_calls, total_calls, date_of_report,time_of_report) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) on duplicate key update total_talk_time_seconds = values(total_talk_time_seconds), total_talk_time_minutes = values(total_talk_time_minutes), total_inbound = values(total_inbound), total_outbound = values(total_outbound), missed_calls = values(missed_calls), total_calls = values(total_calls), time_of_report = now()") or die(mysqli_error($conn2)); // create main array $content = []; while ($d = mysqli_fetch_array($data, mysqli_assoc)) { mysqli_stmt_bind_param($stmt, "iiidiiiiss", $d['extension'], $d['responsibleuserextensionid'], $d['total_talk_time_seconds'], $d['total_talk_time_minutes'], $d['total_outbound'], $d['total_inbound'], $d['total_missed'], $d['total_calls'], $d['time_of_report'], $d['date_of_report']) or die(mysqli_error($conn2)); mysqli_stmt_execute($stmt) or die(mysqli_error($conn2)); // store current row $content[] = $d; } // store file_put_contents('ambitionlog.json', json_encode($content, json_pretty_print | json_force_object));
the original query inserting/updating in workbench:
insert test.ambition_test (extension, extid, total_talk_time_seconds, total_talk_time_minutes, total_outbound, total_inbound, missed_calls, total_calls, time_of_report, date_of_report) select c.extension, responsibleuserextensionid, sum(duration), round(sum(duration) / 60,2), sum(if(legtype1 = 1,1,0)), sum(if(legtype1 = 2,1,0)), sum(if(answered = 1,0,1)) -- , count(distinct b.notablecallid) total_calls , sum(if(legtype1 = 1,1,0)) + sum(if(legtype1 = 2,1,0)) total_calls, now(), curdate() cdrdb.session left join cdrdb.callsummary b on a.notablecallid = b.notablecallid left join cdrdb.mxuser c on a.responsibleuserextensionid = c.extensionid b.ts >= curdate() , c.extension in (7295, 7306, 7218, 7247, 7330, 7000, 7358) group c.extension on duplicate key update total_talk_time_seconds = values (total_talk_time_seconds) , total_talk_time_minutes = values (total_talk_time_minutes) , total_outbound = values (total_outbound) , total_inbound = values (total_inbound) , missed_calls = values (missed_calls) , total_calls = values (total_calls) , time_of_report = now();
Comments
Post a Comment