Location: PHPKode > scripts > Handle remote data with PHP 5 and REST Web service > handle-remote-data-with-php-5-and-rest-web-service/server/classes/ServerMainContent.class.php
<?php

interface MainContents {
	// Funktion ShowRecords wird unter Commander aufgerufen
	public function showAllRemoteRecords();
	public function showSingleRemoteRecord($id);
}

class ServerMainContent extends ServerDataGateway implements MainContents {
	protected $db;
	protected $res;
	protected $user;
	protected $id;
	protected $acoount;
	protected $ipaddress;
	protected $message;
	protected $dbhtml;

	public function __construct() {

    	// set database connection
        $dbconn = new ServerDBConn();
		$this->db = $dbconn->connectDB();
	}

	public function showAllRemoteRecords() {
		$res = '';

		if($res = $this->db->query("SELECT login_id,user
								FROM tb_restlogin")) {

    		while ($row = $res->fetch_assoc()) {
    			$this->id		= $row['login_id'];
				$this->user 	= $row['user'];

    			$this->dbhtml .= "{$this->getId()}\r";
    			$this->dbhtml .= "{$this->getUser()}\n";

			}
			return $this->dbhtml;

			if(!$this->db->affected_rows) {
    			die("<font size=\"2\" color=\"red\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">
    					No records found.</font>"); }

    		// close statement and connection
			$res->close();
		}
		else {
    			die("<font size=\"2\" color=\"red\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">
    					Access denied.</font>");
		}

	}

	public function showSingleRemoteRecord($id) {
		$res = '';
		$col1 = '';
		$col2 = '';
		$col3 = '';
		$col4 = '';

		$this->id = $id;

		if ($stmt = $this->db->prepare("SELECT login_id,user,ipaddress
									FROM tb_restlogin
    								WHERE login_id = ?")) {

    		$stmt->bind_param('i', $this->id);

    		// execute prepared statement
			$stmt->execute();

			// bind results to output
			$stmt->bind_result($col1,$col2,$col3);

			// loop result set
    		while ($stmt->fetch()) {
    				$this->id = $col1;
    				$this->user = $col2;
    				$this->ipaddress = $col3;

    				$this->dbhtml .= "{$this->getId()}\r";
    				$this->dbhtml .= "{$this->getUser()}\n";
    				$this->dbhtml .= "{$this->getIpaddress()}\n";
    		}
    		return $this->dbhtml;

			if(!$this->db->affected_rows) {
    			die("<font size=\"2\" color=\"red\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">
    					No records found.</font>");
			}
			// close statement and connection
			$stmt->close();
  		}
  		else {
    			die("<font size=\"2\" color=\"red\" face=\"Arial,Helvetica,Geneva,Swiss,SunSans-Regular\">
    					Access denied.</font>");
			}
	}

}
  ?>
Return current item: Handle remote data with PHP 5 and REST Web service