Welcome Guest, Not a member yet? Register   Sign In
Inherited code works but I'm convinced it can't...magic?
#1

[eluser]Unknown[/eluser]
This function returns the error “no column ‘week’ in ‘field list’” when I test it in isolation. I know why it’s doing it (the IMPORT table has no column called ‘week’) but fail to see how it could ever run successfully. The db->insert() function receives a table name and an array where the keys are the column headers and the values are the data to put in those columns. As the keys in $data (including ‘week’) are hardcoded it should return this error every time. However, I inherited this code on starting a new job and have every reason to believe it works and has been since I arrived - the return value is needed elsewhere and I know those parts work.

private function updateDatabaseStats($start_time, $filename, $nolines)
{
$file = get_filename($filename, true);
$error_file = (file_exists($this->error_file)) ? get_filename($this->error_file, true) : NULL;
$imported_rows = $nolines - $this->errorCount;
$state = ($nolines == $imported_rows) ? “SUCCESS” : “ERROR”;
//Collect all the data.
$data = array(‘original_file’ => $file, ‘error_file’ => $error_file,
‘import_start’ => $start_time, ‘import_finish’ => time(),
‘week’ => date(“W”, $start_time), ‘year’ => date(“Y”, $start_time),
‘total_rows’ => $nolines, ‘imported_rows’ => $imported_rows,
‘import_state’ => $state);
//Insert the data into the database.
$this->CI->db->insert(‘IMPORTS’, $data);
return $this->CI->db->insert_id();
}

Have you any clue as to how this function can be running without returning the error?

Thanks
#2

[eluser]Unknown[/eluser]
OK, I've solved it. I have two databases, production and development. The production one has the week column so it works most of the time but the development one was out of date - missing the column - so it doesn't work when using that database.




Theme © iAndrew 2016 - Forum software by © MyBB