Zed:IQuery
Aus ProjectGames Wiki
Mit dem Interface IQuery ist es möglich eine eigene Query-Helper Klasse zu schreiben. Diese kann dann auch an die Query-Methode von IDatabase übergeben werden.
Inhaltsverzeichnis |
Implementierung
Definition
interface IQuery { /** * Get the Query * * @return string Returns the final Query as string */ public function GetQuery(); }
Beispielimplementierung
class SelectQuery implements IQuery { private $_query; /** * Create an Instance of SelectQuery * * @param string $table Name of the Table * @param array $keys optional Name of Columns */ public function __construct($table, $keys=null) { $columns = ($keys == null ? "*" : implode(",", $keys)); $this->_query = "SELECT ".$columns." FROM ".$table; } /* * IQuery */ public function GetQuery() { return $this->_query; } /* * end */ } // USAGE: $query = new SelectQuery("testtable", Array("column1", "column2")); echo $query->GetQuery(); // SELECT column1,column2 FROM testtable
Verwendung mit Zed:Database
// now lets send our IQuery to the sql server $database = new Database("localhost", "test", "username", "password"); $database->Query($query);
Kategorie: Zed
