MySQL call from PHP (CodeIgniter) not working right -
i'm new php (and codeigniter) , i'm having trouble trying simple call of $this->db->query() work. in code (see bottom of post) looking through errors , warnings have been logged in database table eventlog , comparing each list of accepted error messages. if message isn't found on list, want acknowledge setting "ack = 't'". code can't run , gives message:
error number: 1064
you have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 1
update eventlog set ack = 't' id =
this message seems indicate "$row['id']" not working way intended. should give me id of error or warning, error suggests it's giving nothing, or in wrong format. missing? or there better way may bypass problem?
my code:
$acceptedmessages = array("whatever", "whateverelse" ); $sql = "(select id, mesg eventlog level = 'error') union (select id, mesg eventlog level 'warn%')" ; foreach ($this->db->query($sql) $row) { foreach ($acceptedmessages $messagepart) { $pos = strpos($row['mesg'], $messagepart); if ($pos !== false) { continue 2; } } // if here eventlog message didn't match accepted messages, // acknowledge $idnum = $row['id']; $sql3 = "update eventlog set ack = 't' id = " . $idnum; $res = $this->db->query($sql3); if (!$res) { echo "failed acknowledge error/warning id " . $row['id'] . " in eventlog"; } }
$this->db->query($sql)
returns result object, not array, foreach shouldn't working. try instead:
$query = $this->db->query($sql); foreach ($query->result_array() $row) {
check out docs more options: http://ellislab.com/codeigniter/user-guide/database/results.html
Comments
Post a Comment