我有一個Flash應用程序,它使用單個php文件從數據庫檢索記錄(使用Zend框架)。當應用程序第一次開始時,我打電話給php來設置一個類變量,以便將來對數據庫的所有請求都將使用此變量根據其值選擇記錄。因此,這裏的類是如何開始的:Zend PHP類可變保留MySQL查詢
class MyClass
{
private $animal = "";
public function setAnimal($anim) {
$this->animal = $anim;
echo($this->animal); //this correctly prints the variable I passed in
}
後來,根據用戶的輸入,我做出此一等級不同方法的調用,但它彷彿類變量$動物已經被人遺忘,因爲它沒有不再有對類的任何後續訪問值:
public function getAnimals()
{
echo('getAnimals: ');
echo($this->animal); //this prints nothing - as if it doesn't know what "animal" is
$result = mysql_query("SELECT * FROM animals WHERE animal='$this->animal'"); //and therefore this query doesn't work
$t = array();
while($row = mysql_fetch_assoc($result))
{
array_push($t, $row);
}
return $t;
}
所以我的問題是,我怎樣才能得到一個PHP類變量堅持這樣我就可以將它設置一次,我可以在任何時候訪問應用程序的生命?
是的,這就是我所害怕的。看起來我必須對會話和flash進行一些研究。謝謝。 – sol 2010-01-09 22:04:10