Sunday, 15 May 2011

mysql - How to get an array from a class in PHP? -



mysql - How to get an array from a class in PHP? -

i newbie, please forgive inexperienced knowledges. have class in php. makes database job. couldn't results array. public function __construct($sunucu, $kullaniciadi, $kullanicisifre, $veritabaniadi){ $this->_baglanti= mysql_connect($sunucu, $kullaniciadi,$kullanicisifre); mysql_select_db($veritabaniadi,$this->_baglanti); } public function baglantiyikopar(){ mysql_close($this->_baglanti); } public function sorgula($sorgu){ $this->_donensonuclar = mysql_query($sorgu, $this->_baglanti); $this->_satirsayisi = mysql_num_rows($this->_donensonuclar) ; } public function satirsayisi(){ homecoming $this->_satirsayisi; } public function satirlar(){ $satirlar = array(); for($st=0;$st< $this->_satirsayisi;$st++){ $satirlar = mysql_fetch_assoc($this->_donensonuclar); } homecoming $satirlar; } } ?>

assuming mean function, need alter little bit:

public function satirlar(){ $satirlar = array(); for($st=0;$st< $this->_satirsayisi;$st++){ $satirlar[] = mysql_fetch_assoc($this->_donensonuclar); ^^ add together new entry array instead of overwriting existing 1 } homecoming $satirlar; }

also note mysql_* functions deprecated , recommended switch pdo (or mysqli) prepared statements , bound variables.

php mysql

No comments:

Post a Comment