I’m testing a conversion of our site’s database from Sql Server to MySQL on a Cake PHP 1.2 site, and I’ve run into an error in how cake is storing my model’s info now. When creating my “emp” (employee, not my naming scheme) model I get the following error now:
Notice (8): Undefined index: id [CORE\app\models\emp.php, line 83]
Here is the code generating the SQL and that should be populating the model’s data
function findInfo($ecode = false) {
/*The SQL statement*/
$sql = "Select id as 'Emp__id', code as 'Emp__code',
first_name as 'Emp__first_name', last_name as 'Emp__last_name',
created as 'Emp__created', modified as 'Emp__modified',
password as 'Emp__password', active as 'Emp__active',
hidden_flag as 'Emp__hidden_flag'
from rs_emp as Emp
where code Like '$ecode' limit 1";
$employee = $this->query($sql);
$employee = $employee[0];
/*the below lines return the undefined index error
$employee['Permission'] = $this->findPermissions($employee['Emp']['id']);
$employee['Plant'] = $this->findPlants($employee['Emp']['id']);
return $employee;
}
The error means that it’s not finding $employee[‘Emp’][‘id’], I assumed the Select id as 'Emp__id' statements took care of that, as the old code worked. Is this something that can be corrected?
I assume this would NOT be a problem if custom queries were removed and instead Cake’s query system were used, correct? The only reason I haven’t started replacing them myself is I’m not sure how and I didn’t build the system, if there’s a super quick fix to the above sql statement I’ll do that, I’m currently testing to see how easy it would be to move us to MySQL, but long term I do plan to move over to Cake’s query model.
I had made the mistake of assuming the
Select id as 'Emp__id'method was correct; it wasn’t. Simply removing theasstatements solved this problem, the array now reads the properly named indexes. I just don’t know why the as statements were ever included.