Add a find_all function to return an array of Server objects

This commit is contained in:
Isaac Connor 2015-12-31 10:13:48 -05:00
parent bfe4175fdf
commit 12ee147bc7
1 changed files with 10 additions and 0 deletions

View File

@ -1,6 +1,7 @@
<?php
require_once( 'database.php' );
class Server {
public function __construct( $IdOrRow = NULL ) {
$row = NULL;
if ( $IdOrRow ) {
@ -22,6 +23,15 @@ class Server {
$this->{'Hostname'} = '';
}
}
public static function find_all() {
$servers = array();
$result = dbQuery( 'SELECT * FROM Servers ORDER BY Name');
$results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server' );
foreach ( $results as $row => $server_obj ) {
$servers[] = $server_obj;
}
return $servers;
}
public function Url() {
return ZM_BASE_PROTOCOL . '://'. $this->Hostname();