<?php class chatClass{ public static function getRestChatLines($id){ global $db_host,$db_user,$db_pass,$db_base; $arr = array(); $jsonData = '{"results":['; $db_connection = new mysqli( $db_host, $db_user, $db_pass, $db_base); $db_connection->query( "SET NAMES 'UTF8'" ); $statement = $db_connection->prepare( "SELECT id, absender, nachricht, time FROM vms_chat WHERE id > ? "); $statement->bind_param( 'i', $id); $statement->execute(); $statement->bind_result( $id, $usrname, $chattext, $chattime); $line = new stdClass; while ($statement->fetch()) { $line->id = $id; $line->usrname = $usrname; $line->chattext = $chattext; $line->chattime = date('H:i:s', $chattime); $arr[] = json_encode($line); } $statement->close(); $db_connection->close(); $jsonData .= implode(",", $arr); $jsonData .= ']}'; return $jsonData; } public static function setChatLines( $chattext, $usrname, $color) { global $db_host,$db_user,$db_pass,$db_base; $db_connection = new mysqli( $db_host, $db_user, $db_pass, $db_base); $db_connection->query( "SET NAMES 'UTF8'" ); $statement = $db_connection->prepare( "INSERT INTO chat( usrname, color, chattext) VALUES(?, ?, ?)"); $statement->bind_param( 'sss', $usrname, $color, $chattext); $statement->execute(); $statement->close(); $db_connection->close(); } } ?>