initialize(MY_DSN, __CLASS__, $id); } /** * Returns an array of Product objects, all of them * * @return array of Product */ public static function getAll() { #if ( !$name ) # return new Error(ERROR_IMPROPERUSE); $result = parent::connect(MY_DSN); if ( Error::isError($result) ) { return $result; } $aDB = parent::$aDB[MY_DSN]; $aSQL = "SELECT * FROM Product"; $aResult = $aDB->query($aSQL); if ( DB::isError($aResult) ) return new Error(ERROR_BADQUERY, $aSQL); $aProducts = array(); while ( $aRow = $aResult->fetchRow() ) $aProducts[] = new Product($aRow); return $aProducts; } /** * Returns an array of Shopper objects owned by this Product * * @return array of Shopper */ public function getShoppers() { #if ( !$name ) # return new Error(ERROR_IMPROPERUSE); $result = parent::connect(MY_DSN); if ( Error::isError($result) ) { return $result; } $aDB = parent::$aDB[MY_DSN]; $aSQL = "SELECT s.* FROM Shopper s INNER JOIN Shopper_Product sp ON (s.sid=sp.sid) INNER JOIN Product p ON (sp.pid=p.pid) WHERE p.pid=".$this->getField('pid'); $aResult = $aDB->query($aSQL); if ( DB::isError($aResult) ) return new Error(ERROR_BADQUERY, $aSQL); $aProducts = array(); while ( $aRow = $aResult->fetchRow() ) $aProducts[] = new Product($aRow); return $aProducts; } } ?>