I'm new to PHP (and CodeIgniter) and I'm having trouble trying to get a simple call of $this->db->query() to work. In my code (see bottom of post) I am looking through the errors and warnings that have been logged in my database table eventLog and comparing each to a list of accepted error messages. If any message isn't found to be on that list, then I want to acknowledge it by setting "ack = 't'". However the code can't successfully run and gives the message:
Error Number: 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 '' at line 1
UPDATE eventLog SET ack = 't' WHERE id =
This message seems to indicate that "$row['id']" is not working the way I intended. It should give me the id of the error or warning, but the error suggests that it's giving nothing, or in the wrong format. What am I missing? Or is there a better way to do this that may bypass my problem?
MY CODE:
$acceptedMessages = array("whatever",
"whateverelse"
);
$sql = "(SELECT id, mesg FROM eventLog WHERE level = 'error') UNION
(SELECT id, mesg FROM eventLog WHERE level LIKE 'warn%')" ;
foreach ($this->db->query($sql) as $row) {
foreach ($acceptedMessages as $messagePart) {
$pos = strpos($row['mesg'], $messagePart);
if ($pos !== false) {
continue 2;
}
}
// if we get here the eventLog message didn't match any accepted messages, so
// acknowledge it
$idNum = $row['id'];
$sql3 = "UPDATE eventLog SET ack = 't' WHERE id = " . $idNum;
$res = $this->db->query($sql3);
if (!$res) { echo "Failed to acknowledge error/warning with id " . $row['id'] . " in eventLog"; }
}