function getUnknownError($operation, $errorMessage, $format = "xml") { $code = -100; $message = $errorMessage; if ($format == "json") { return json_encode(array('operation' => $operation, 'code' => $code, 'message' => $message)); } else { return getResultXML($operation, $code, $message); } }
function getChatMessagesAfterTimestamp($method, $format, $timestamp) { $resultCode = 0; if ($format == "json") { $output = array(); } else { $output = ""; } $query = sprintf("SELECT * FROM chatmessages WHERE `received` >= %d", $timestamp); error_log($query); // Perform Query $result = mysql_query($query); // Check result // This shows the actual query sent to MySQL, and the error. Useful for debugging. if (!$result) { $resultCode = -1; if ($format == "json") { $output = array('error' => 'Invalid query: ' . mysql_error() . "\n" . 'Whole query: ' . $query); } else { $output = "<error>"; $output .= 'Invalid query: ' . mysql_error() . "\n"; $output .= 'Whole query: ' . $query; $output .= "</error>"; } } else { $resultCode = 0; while ($row = mysql_fetch_assoc($result)) { if ($format == "json") { array_push($output, array('id' => $row['id'], 'username' => $row['username'], 'received' => $row['received'], 'message' => $row['message'], 'ipaddress' => $row['ipaddress'])); } else { $output .= "<ChatMessage>"; $output .= "<id>" . $row['id'] . "</id>"; $output .= "<username>" . $row['username'] . "</username>"; $output .= "<received>" . $row['received'] . "</received>"; $output .= "<message>" . $row['message'] . "</message>"; $output .= "<ipaddress>" . $row['ipaddress'] . "</ipaddress>"; $output .= "</ChatMessage>"; } } } if ($format == "json") { echo json_encode(array('operation' => $method, 'code' => $resultCode, 'message' => $output)); } else { echo getResultXML($method, $resultCode, $output); } mysql_close(); }