Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Last active June 16, 2022 20:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoMan2000/0ee7fbf41f69a7ae4cdc555241e2e5f6 to your computer and use it in GitHub Desktop.
Save NoMan2000/0ee7fbf41f69a7ae4cdc555241e2e5f6 to your computer and use it in GitHub Desktop.
Crashing mysqli in php.

Success and Fail

The mysqliError file will fail when the sub-query is used with the prepare statement. This is perfectly valid MySQL syntax to first get an ordered result set, then further filter it, i.e. get the last twenty-four records but then order them by date ascending, but the prepare method does not like it.

The other feature is the size of the query. Removing all of the various select statements will coerce it into working. This is a bug that was introduced recently, this same code worked before updating PHP to the latest version.

[New LWP 1831]
Core was generated by `php-fpm: pool www '.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00007f71a83f8c22 in ?? ()
CREATE TABLE `realtripmonthlyentitysite` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`phoneCount` int(10) NOT NULL,
`triggerCount` int(10) NOT NULL,
`tripDay` datetime NOT NULL,
`entityID` int(10) unsigned NOT NULL,
`siteID` int(10) unsigned NOT NULL,
`drivingScore` double unsigned NOT NULL,
`phoneScore` double unsigned NOT NULL,
`ecoScore` double unsigned NOT NULL,
`mileage` double NOT NULL,
`brake1` int(10) unsigned NOT NULL,
`brake2` int(10) unsigned NOT NULL,
`brake3` int(10) unsigned NOT NULL,
`accel8` int(10) unsigned NOT NULL,
`accel9` int(10) unsigned NOT NULL,
`accel10` int(10) unsigned NOT NULL,
`accel11` int(10) unsigned NOT NULL,
`accel12` int(10) unsigned NOT NULL,
`over70` int(10) unsigned NOT NULL,
`over80` int(10) unsigned NOT NULL,
`over90` int(10) unsigned NOT NULL,
`brake7` int(10) unsigned NOT NULL,
`brake8` int(10) unsigned NOT NULL,
`brake9` int(10) unsigned NOT NULL,
`brake10` int(10) unsigned NOT NULL,
`brake11` int(10) unsigned NOT NULL,
`brake12` int(10) unsigned NOT NULL,
`brake13` int(10) unsigned NOT NULL,
`phoneversion` varchar(45) NOT NULL,
`tBlockWindow` int(10) unsigned NOT NULL,
`tTalkTime` int(10) unsigned NOT NULL,
`tTalkHandFreeTime` int(10) unsigned NOT NULL,
`tScreenOnTime` int(10) unsigned NOT NULL,
`tUnlockedTime` int(10) unsigned NOT NULL,
`tTotalAppTime` int(10) unsigned NOT NULL,
`tTotalAllowedAppTime` int(10) unsigned NOT NULL,
`tTotalCallsIncomming` int(10) unsigned NOT NULL,
`tTotalCallsOutgoing` int(10) unsigned NOT NULL,
`tTotalSMSIn` int(10) unsigned NOT NULL,
`tTotalSMSOut` int(10) unsigned NOT NULL,
`tDriver` int(10) unsigned NOT NULL,
`tAppsBlocked` int(10) unsigned NOT NULL,
`idleTime` int(10) unsigned NOT NULL DEFAULT '0',
`pointsEarned` int(10) unsigned NOT NULL DEFAULT '0',
`triggerVersion` varchar(10) NOT NULL DEFAULT 'F9',
`totalTrips` int(10) unsigned NOT NULL DEFAULT '0',
`totalDrivingTime` int(10) unsigned NOT NULL DEFAULT '0',
`lastModified` datetime NOT NULL,
`idle30` int(10) unsigned NOT NULL DEFAULT '0',
`idle60` int(10) unsigned NOT NULL DEFAULT '0',
`idle90` int(10) unsigned NOT NULL DEFAULT '0',
`idle120` int(10) unsigned NOT NULL DEFAULT '0',
`idle300` int(10) unsigned NOT NULL DEFAULT '0',
`averageSpeed` int(10) unsigned NOT NULL DEFAULT '0',
`maxSpeed` int(10) unsigned NOT NULL DEFAULT '0',
`callAllowOut` int(10) unsigned NOT NULL DEFAULT '0',
`callAllowIn` int(10) unsigned NOT NULL DEFAULT '0',
`callBlockOut` int(10) unsigned NOT NULL DEFAULT '0',
`callBlockIn` int(10) unsigned NOT NULL DEFAULT '0',
`dbAvg` int(10) unsigned NOT NULL DEFAULT '0',
`dbMax` int(10) unsigned NOT NULL DEFAULT '0',
`utilization` double DEFAULT '0',
`uYear` int(11) NOT NULL DEFAULT '0',
`uMonth` int(11) NOT NULL DEFAULT '0',
`uWeek` int(11) NOT NULL DEFAULT '0',
`uDay` int(11) NOT NULL DEFAULT '0',
`accelComposite` double DEFAULT '100',
`lateralComposite` double DEFAULT '100',
`brakeComposite` double DEFAULT '100',
`corneringComposite` double DEFAULT '100',
`speedAlertComposite` double DEFAULT '100',
`appScore` double DEFAULT '100',
`talkScore` double DEFAULT '100',
`leftturns` double DEFAULT '0',
`rightturns` double DEFAULT '0',
PRIMARY KEY (`entityID`,`siteID`,`uYear`,`uMonth`,`tBlockWindow`),
UNIQUE KEY `id_UNIQUE` (`id`),
KEY `entity_index` (`entityID`,`siteID`,`tripDay`,`tDriver`),
KEY `day_index` (`tripDay`,`tDriver`),
KEY `idx2` (`entityID`,`siteID`,`tDriver`,`uYear`,`uMonth`),
KEY `idx3` (`entityID`,`siteID`,`uYear`,`uMonth`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
INSERT INTO realtripmonthlyentitysite (id, phoneCount, triggerCount, tripDay, entityID, siteID, drivingScore, phoneScore, ecoScore, mileage, brake1, brake2, brake3, accel8, accel9, accel10, accel11, accel12, over70, over80, over90, brake7, brake8, brake9, brake10, brake11, brake12, brake13, phoneversion, tBlockWindow, tTalkTime, tTalkHandFreeTime, tScreenOnTime, tUnlockedTime, tTotalAppTime, tTotalAllowedAppTime, tTotalCallsIncomming, tTotalCallsOutgoing, tTotalSMSIn, tTotalSMSOut, tDriver, tAppsBlocked, idleTime, pointsEarned, triggerVersion, totalTrips, totalDrivingTime, lastModified, idle30, idle60, idle90, idle120, idle300, averageSpeed, maxSpeed, callAllowOut, callAllowIn, callBlockOut, callBlockIn, dbAvg, dbMax, utilization, uYear, uMonth, uWeek, uDay, accelComposite, lateralComposite, brakeComposite, corneringComposite, speedAlertComposite, appScore, talkScore, leftturns, rightturns)
VALUES
('1201247', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2020', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('12280', '1', '1', '2014-04-03 00:00:00', '33', '7259', '100', '100', '100', '0.002', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '2', '0', '0', 'none', '2', '625', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2021', '4', '13', '3', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('1726163', '1', '1', '2014-04-08 00:00:00', '33', '7259', '100', '98', '100', '0.009', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '129', '129', '129', '0', '0', '0', '0', '1', '9', '0', '0', 'none', '9', '4301', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '1', '10', '0', '0', '0', '2', '0', '0', '0', '2022', '4', '14', '8', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('1726164', '1', '1', '2014-04-08 00:00:00', '33', '7259', '100', '100', '100', '0.03', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '20', '20', '20', '0', '0', '0', '0', '1', '30', '0', '0', 'none', '30', '23469', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '1', '22', '0', '0', '0', '0', '0', '0', '0', '2023', '4', '14', '8', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('13453', '1', '1', '2014-04-15 00:00:00', '33', '7259', '100', '100', '100', '0.005', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '11', '11', '11', '0', '0', '0', '0', '1', '5', '0', '0', 'none', '5', '5094', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2024', '4', '15', '15', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('14862', '1', '1', '2014-04-30 00:00:00', '33', '7259', '100', '100', '100', '0.001', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', 'none', '1', '10816', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2025', '4', '17', '30', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('274454', '1', '1', '2014-07-09 00:00:00', '33', '7259', '100', '100', '100', '0.007', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '110', '110', '0', '0', '0', '0', '0', '1', '15', '0', '0', 'none', '7', '33292', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '2', '11', '0', '0', '0', '0', '0', '0', '0', '2026', '7', '27', '9', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('362057', '1', '1', '2014-07-23 00:00:00', '33', '7259', '100', '100', '100', '0.021', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '47', '47', '0', '0', '0', '0', '0', '1', '49', '0', '0', 'none', '21', '25110', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '2', '38', '0', '0', '0', '0', '0', '0', '0', '2027', '7', '29', '23', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('9', '1', '1', '2013-05-10 00:00:00', '33', '7259', '100', '88', '100', '17', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '458', '23', '23', '0', '1', '0', '0', '1', '5', '0', '0', 'none', '17', '8527', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2040', '5', '18', '10', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('3430', '1', '1', '2013-11-21 00:00:00', '33', '7259', '79', '97', '89', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '46', '0', '0', '0', '0', '0', '0', '1', '1', '87', '1', 'none', '1', '408', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2041', '11', '46', '21', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('75605', '1', '1', '2013-05-10 00:00:00', '33', '7259', '100', '88', '100', '17', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '458', '23', '23', '0', '1', '0', '0', '1', '5', '0', '0', 'none', '17', '8527', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2042', '5', '18', '10', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('235625', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2028', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('557489', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2029', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('544975', '1', '1', '2014-04-09 00:00:00', '33', '7259', '100', '100', '100', '0.01', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '10', '8485', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2030', '4', '14', '9', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('545031', '1', '1', '2014-04-15 00:00:00', '33', '7259', '100', '100', '100', '0.005', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '11', '11', '11', '0', '0', '0', '0', '1', '5', '0', '0', 'none', '5', '5094', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2031', '4', '15', '15', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('545134', '1', '1', '2014-04-30 00:00:00', '33', '7259', '100', '100', '100', '0.001', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '0', 'none', '1', '10816', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2032', '4', '17', '30', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('545733', '1', '1', '2014-07-09 00:00:00', '33', '7259', '100', '100', '100', '0.007', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '110', '110', '0', '0', '0', '0', '0', '1', '15', '0', '0', 'none', '7', '33292', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '2', '11', '0', '0', '0', '0', '0', '0', '0', '2033', '7', '27', '9', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('545873', '1', '1', '2014-07-23 00:00:00', '33', '7259', '100', '100', '100', '0.021', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '47', '47', '0', '0', '0', '0', '0', '1', '49', '0', '0', 'none', '21', '25110', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '2', '38', '0', '0', '0', '0', '0', '0', '0', '2034', '7', '29', '23', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('273195', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2035', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('312593', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2036', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('317373', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2037', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('333158', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2038', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('369957', '1', '1', '2014-03-18 00:00:00', '33', '7259', '100', '99', '100', '0.003', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'none', '1', '0', '0', '0', '148', '148', '6', '0', '0', '0', '0', '1', '10', '0', '0', 'none', '3', '8590', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '5', '16', '0', '0', '0', '0', '0', '0', '0', '2039', '3', '11', '18', '100', '100', '100', '100', '100', '100', '100', '0', '0'),
('766', '1', '2', '2013-08-08 00:00:00', '33', '7259', '99', '80', '48', '388', '1', '0', '0', '0', '0', '0', '0', '0', '8343', '717', '0', '1', '0', '0', '0', '0', '0', '0', 'none', '1', '13548', '0', '0', '12631', '11738', '11723', '23', '52', '6', '0', '1', '41', '2854', '203', 'none', '19', '28229', '0000-00-00 00:00:00', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '2055', '8', '31', '8', '100', '100', '100', '100', '100', '100', '100', '0', '0');
$foo = new MySQLIReadSingleton(); // This has user, password, etc.
$entityID = 33;
$query = "(SELECT COUNT(id) AS numDays,
DATE_FORMAT(DATE_ADD(
MAKEDATE(YEAR(tripDay), 1),
INTERVAL MONTH(tripDay) - 1 MONTH),'%c/%e/%y') AS dWeek,
ROUND(SUM(phoneCount)) AS sPhones,
ROUND(SUM(triggerCount)) AS sTriggers,
tripDay,
ROUND(SUM(totalTrips)) AS totTrips,
ROUND(SUM(drivingScore * mileage) / SUM(mileage)) AS dScore,
ROUND(SUM(phoneScore * mileage) / SUM(mileage)) AS pScore,
ROUND(SUM(ecoScore * mileage) / SUM(mileage)) AS eScore,
ROUND(SUM(pointsEarned)) AS points,
ROUND(
IF('imperial' = 'metric', SUM(mileage) * 1.60934, SUM(mileage))
) AS totMiles,
ROUND(SUM(tTotalSMSIn)) totSMS,
ROUND(SUM(tAppsBlocked)) AS tAppsBlocked,
ROUND(SUM(brake7) + SUM(brake8) + SUM(brake9)) AS tBrake1,
ROUND(SUM(brake10) + SUM(brake11) + SUM(brake12)) AS tBrake2,
ROUND(SUM(brake13)) AS tBrake3,
ROUND(SUM(over70)) AS tOver70,
ROUND(SUM(over80)) AS tOver80,
ROUND(SUM(over90)) AS tOver90,
ROUND(SUM(tTalkTime)) AS talkTime,
ROUND(SUM(tTalkHandFreeTime)) AS handsFree,
ROUND(SUM(tTotalAppTime)) AS appTime,
ROUND(SUM(tTotalAllowedAppTime)) AS appAllowedTime,
ROUND(SUM(pointsEarned)) AS totalPoints,
ROUND(SUM(totalDrivingTime)) AS drivingTime,
ROUND(SUM(over70)) AS tOver70,
ROUND(SUM(idle30)) AS tidle30,
ROUND(SUM(idle60)) AS tidle60,
ROUND(SUM(idle90)) AS tidle90,
ROUND(SUM(idle120)) AS tidle120,
ROUND(SUM(idle300)) AS tidle300,
ROUND(
IF('imperial' = 'metric', AVG(averageSpeed) * 1.60934, AVG(averageSpeed))
) AS taverageSpeed,
ROUND(
IF('imperial' = 'metric', MAX(maxSpeed) * 1.60934, MAX(maxSpeed))
) AS tmaxSpeed,
ROUND(SUM(dbAvg)) AS tdbAvg,
ROUND(MAX(dbMax)) AS tdbMax,
ROUND(SUM(utilization)) AS tutilization,
ROUND(SUM(callAllowIn) + SUM(callAllowOut)) AS tAllowedCalls,
ROUND(SUM(callBlockIn) + SUM(callBlockOut)) AS totCalls
FROM realtripmonthlyentitysite AS r
WHERE entityID = ? AND
siteID IN (7259,18516,325,443,18148,19241,12032,12048,18169,1838,1853,12047,11529,23584,23730,23734,24564,24712,12033,16627,19033,19239,21706,21956,22013)
GROUP BY YEAR(tripDay),
MONTH(tripDay) ORDER BY YEAR(tripDay) DESC,
MONTH(tripDay) DESC LIMIT 24)
ORDER BY YEAR(tripDay), MONTH(tripDay) ";
try {
$x = $foo->prepare($query);
} catch (\Exception $e) {
echo $e->getMessage() . $query;
// mysqli_stmt::__construct(): Unknown type 18 sent by the server. Please send a report to the developers
}
$foo = new MySQLIReadSingleton(); // This has user, password, etc.
$entityID = 33;
$query = "(SELECT COUNT(id) AS numDays,
DATE_FORMAT(DATE_ADD(
MAKEDATE(YEAR(tripDay), 1),
INTERVAL MONTH(tripDay) - 1 MONTH),'%c/%e/%y') AS dWeek,
ROUND(SUM(phoneCount)) AS sPhones,
ROUND(SUM(triggerCount)) AS sTriggers,
tripDay,
ROUND(SUM(totalTrips)) AS totTrips,
ROUND(SUM(drivingScore * mileage) / SUM(mileage)) AS dScore,
ROUND(SUM(phoneScore * mileage) / SUM(mileage)) AS pScore,
ROUND(SUM(ecoScore * mileage) / SUM(mileage)) AS eScore,
ROUND(SUM(pointsEarned)) AS points,
ROUND(
IF('imperial' = 'metric', SUM(mileage) * 1.60934, SUM(mileage))
) AS totMiles,
ROUND(SUM(tTotalSMSIn)) totSMS,
ROUND(SUM(tAppsBlocked)) AS tAppsBlocked,
ROUND(SUM(brake7) + SUM(brake8) + SUM(brake9)) AS tBrake1,
ROUND(SUM(brake10) + SUM(brake11) + SUM(brake12)) AS tBrake2,
ROUND(SUM(brake13)) AS tBrake3,
ROUND(SUM(over70)) AS tOver70,
ROUND(SUM(over80)) AS tOver80,
ROUND(SUM(over90)) AS tOver90,
ROUND(SUM(tTalkTime)) AS talkTime,
ROUND(SUM(tTalkHandFreeTime)) AS handsFree,
ROUND(SUM(tTotalAppTime)) AS appTime,
ROUND(SUM(tTotalAllowedAppTime)) AS appAllowedTime,
ROUND(SUM(pointsEarned)) AS totalPoints,
ROUND(SUM(totalDrivingTime)) AS drivingTime,
ROUND(SUM(over70)) AS tOver70,
ROUND(SUM(idle30)) AS tidle30,
ROUND(SUM(idle60)) AS tidle60,
ROUND(SUM(idle90)) AS tidle90,
ROUND(SUM(idle120)) AS tidle120,
ROUND(SUM(idle300)) AS tidle300,
ROUND(
IF('imperial' = 'metric', AVG(averageSpeed) * 1.60934, AVG(averageSpeed))
) AS taverageSpeed,
ROUND(
IF('imperial' = 'metric', MAX(maxSpeed) * 1.60934, MAX(maxSpeed))
) AS tmaxSpeed,
ROUND(SUM(dbAvg)) AS tdbAvg,
ROUND(MAX(dbMax)) AS tdbMax,
ROUND(SUM(utilization)) AS tutilization,
ROUND(SUM(callAllowIn) + SUM(callAllowOut)) AS tAllowedCalls,
ROUND(SUM(callBlockIn) + SUM(callBlockOut)) AS totCalls
FROM realtripmonthlyentitysite AS r
WHERE entityID = ? AND
siteID IN (7259,18516,325,443,18148,19241,12032,12048,18169,1838,1853,12047,11529,23584,23730,23734,24564,24712,12033,16627,19033,19239,21706,21956,22013)
GROUP BY YEAR(tripDay),
MONTH(tripDay) ORDER BY YEAR(tripDay) DESC,
MONTH(tripDay) DESC LIMIT 24)
";
try {
$x = $foo->prepare($query);
echo "Made it."
} catch (\Exception $e) {
echo $e->getMessage() . $query;
// mysqli_stmt::__construct(): Unknown type 18 sent by the server. Please send a report to the developers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment