Improving speed/responsiveness PHP query return encoding

kevin150

New Member
I have the following code as part of a larger web application to search for employees and return the required information. The queries themselves take little to no time to complete and return the result set. What appears to need some improvement is how I am currently encoding the results into an array for json_encode to return to the front end. I am out of ideas for how to improve upon the code (hence my question here). Any ideas would be greatly appreciated!\[code\]<?phprequire_once("class.employee.php");$employee = new Employee();$employeeSearch = $employee->searchEmployees($_REQUEST['q']);$employeeResults = array();$row_array['id'] = $_REQUEST['q'];$row_array['empName'] = $_REQUEST['q'];$row_array['empBusinessTitle'] = '';$row_array['empFacility'] = '';array_push($employeeResults, $row_array);while ($empInfo = $employeeSearch->fetchObject()) { $row_array['id'] = $empInfo->empUserName; $row_array['empName'] = ucwords($empInfo->empName); $row_array['empBusinessTitle'] = $empInfo->empBusinessTitle; $facilityName = $employee->getFacilityIDByAD($empInfo->empUserName); $row_array['empFacility'] = isset($facilityName->facilityName) ? $facilityName->facilityName : ''; array_push($employeeResults, $row_array);}$ret['results'] = $employeeResults;echo json_encode($ret);Class Employee {public function searchEmployees($query) { try { $dbh = new PDO($this->dbDSN, $this->dbUser, $this->dbPass); $statement = $dbh->prepare("SELECT empID, CONCAT(empFirstName,' ',empLastName) as empName, empUserName, empBusinessTitle from $this->tblEmployeePeople where CONCAT(empfirstname,' ',emplastName) LIKE CONCAT('%',:query,'%') and empUserName != ''"); $statement->bindParam(':query', $query); $statement->execute(); $dbh = null; return $statement; } catch (PDOException $e) { echo $e->getMessage(); }}}?>\[/code\]
 
Top