Hello All,
I have the following code that gets log entries and compiles them into an array for viewing later:
When the above function is called, I get an error message that says "Error preparing the 'prepare mysql' statement: Commands out of sync; you can't run this command now". I have been trying to figure out why I am getting this error message but I am coming up short. Can someone help me out? Is this a PHP problem or a MySQL problem?Code:function get_risk_logs($risk_no, $group_id) { // get dates first $stmt = mysqli_prepare($this->db_conn, "select date from risk_logs where risk_no = ? and group_id = ? order by date desc"); if (!$stmt) { echo("Error preparing the 'get_risk_logs: 1' statement: " . mysqli_error($this->db_conn)); exit(); } mysqli_stmt_bind_param($stmt, "ii", $risk_no, $group_id); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $date); while (mysqli_stmt_fetch($stmt)) { $dates[] = $date; } mysqli_stmt_close($stmt); $dates = array_unique($dates); $dates = array_values($dates); /* * for each of the dates in the array above, * put all log information in an array corresponding to that date */ $logs = array(); for ($i = 0; $i < sizeof($dates); $i++) { $tmp_date = strval($dates[$i]); $logs[$i] = array('date'=>$tmp_date, 'info'=>array()); $stmt = mysqli_prepare($this->db_conn, "select risk_no, date, time, user, details from risk_logs where date = ? and risk_no = ? and group_id = ?"); if (!$stmt) { echo("Error preparing the 'get_risk_logs: 2' statement: " . mysqli_error($this->db_conn)); exit(); } mysqli_stmt_bind_param($stmt, "sii", $tmp_date, $risk_no, $group_id); mysqli_stmt_execute($stmt); mysqli_stmt_bind_result($stmt, $risk_no, $date, $time, $user_number, $details); while (mysqli_stmt_fetch($stmt)) { $count = 0; $user_name = $this->get_user_name($user_number); $string = "<b>User:</b> $user_name<p/><b>Time:</b> $time<p/><b>Details:</b> $details<p/>"; $logs[$i]['info'][$count] = $string; $count++; } mysqli_stmt_close($stmt); } return $logs; }
Thanks!


Reply With Quote
Bookmarks