How i make a Stream of a MySQL Table

Notice: This thread is very old.

4 years ago

thundervoice
Member | 11
+
0
-

Hello Guys

Ho i make a Stream of a Mysql Table for a JSON Response? This Response should use for a Angular 1.2 loading Bar in Percantage. Because the latency time is up to 10 seconds.

Something like this:

in ItemsModel something like this:

	public function getAllItems($active = 1){
		$data = new \stdClass();
		try{
			$db = $this->database;
			$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
			$table = $db->query("SELECT * FROM itmes WHERE active = '$active'")->fetchAll();
			$data->items = $table;
			$data->count = $this->database->query("SELECT COUNT(*) AS counter FROM items WHERE active = '$active'")->fetch();
			return $data;
		} catch (\PDOException $ex) {
			$data->message = "Error: ".$ex->getCode();
			$data->error = true;
			return $data;
		}
	}

or like this in ItemsPresenter:

	public function actionItems($id){
		$data = new \stdClass();
		ob_start();

		$data = $this->items->getAllItems($id);

		ob_get_clean();

		$this->sendJson($data);
	}

Is this the Right Way?

Thanks a lot for your Help!

greets thundervoice