An Error occurred while handling another error: yii\web\HeadersAlreadySentException: Headers already sent in /home/mgcelectro/public_html/mgcCentralFiles/CommonFunctions.php on line 789. in /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/web/Response.php:368 Stack trace: #0 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/web/Response.php(341): yii\web\Response->sendHeaders() #1 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send() #2 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/ErrorHandler.php(135): yii\web\ErrorHandler->renderException(Object(yii\db\Exception)) #3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\db\Exception)) #4 {main} Previous exception: PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY e.DepartmentID ORDER BY d.CardColor ASC' at line 1 in /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Command.php:1302 Stack trace: #0 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement->execute() #1 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Command.php(1168): yii\db\Command->internalExecute('SELECT e.Depart...') #2 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Command.php(410): yii\db\Command->queryInternal('fetchAll', NULL) #3 /home/mgcelectro/public_html/erpmgc/controllers/SiteController.php(2193): yii\db\Command->queryAll() #4 [internal function]: app\controllers\SiteController->actionIndex(0) #5 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) #6 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array) #7 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('', Array) #8 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('', Array) #9 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest(Object(yii\web\Request)) #10 /home/mgcelectro/public_html/erpmgc/web/index.php(31): yii\base\Application->run() #11 {main} Next yii\db\Exception: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY e.DepartmentID ORDER BY d.CardColor ASC' at line 1 The SQL being executed was: SELECT e.DepartmentID, d.DepartmentName, d.CardColor, sum(e.Gender = 1 ) Male, sum(e.Gender = 2 ) Female, count( * ) total_employees FROM employees e, departments d where e.DepartmentID = d.ID and e.Active = 'Y' and e.ID != 6 and e.MainBranchID = GROUP BY e.DepartmentID ORDER BY d.CardColor ASC in /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Schema.php:676 Stack trace: #0 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'SELECT e.Depart...') #1 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Command.php(1168): yii\db\Command->internalExecute('SELECT e.Depart...') #2 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/db/Command.php(410): yii\db\Command->queryInternal('fetchAll', NULL) #3 /home/mgcelectro/public_html/erpmgc/controllers/SiteController.php(2193): yii\db\Command->queryAll() #4 [internal function]: app\controllers\SiteController->actionIndex(0) #5 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array) #6 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array) #7 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('', Array) #8 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('', Array) #9 /home/mgcelectro/public_html/erpmgc/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest(Object(yii\web\Request)) #10 /home/mgcelectro/public_html/erpmgc/web/index.php(31): yii\base\Application->run() #11 {main} Additional Information: Array ( [0] => 42000 [1] => 1064 [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY e.DepartmentID ORDER BY d.CardColor ASC' at line 1 )