<?php

namespace Core;

/**
 * Generic database provider class interface
 * 
 * @author Zoltraks <zoltarx@o2.pl>
 */
interface Provider
{
	/**
	 * Open database connection
	 * @return bool
	 */
	function open();
	
	/**
	 * Close database connection
	 * @return bool
	 */
	function close();

	/**
	 * Execute SQL query
	 * @param string $query
	 * @return bool
	 */
	function query($query);
	
	/**
	 * Read current record and move to next one
	 * @return array Record data or false if there is no data left
	 * @example while ($row = $Data->row()) { print_r($row); }
	 */
	function row();

	/**
	 * Read all rows in an array, empty array() even if there are no results.
	 * This way foreach will never fail when used in following short usage example.
	 * @example foreach ($Data->all() as $row) { print_r($row); }
	 * @return array Array of record
	 */
	function all();
	
	/**
	 * Read exactly one value
	 */
	function scalar();
	
	/**
	 * Execute SQL statement with no results
	 * @param string $statement
	 */
	function execute($statement);
}

if ($Data->query("SELECT 1"))
{
	foreach ($Data->row() as $column => $value)
	{	
	}
}
