Query "SELECT * FROM uzytownik" in phpMyAdmin gives me all recodrs from uzytkownik table. But this same query applied in yii controller gives me olny one (first) record. What is wrong?
class StronaController extends CController
{
public function actionIndex()
{
$model = new Uzytkownik;
$wynik = $model::model()->findBySQL('SELECT * FROM uzytkownik');
for($i=0;$i<count($wynik);$i++)
{
echo count($wynik).' '.$wynik ->imie.'<br>';
}
}
}
Output: 1 Jan
Query with WHERE conditions gives me also one record, but it should gives me three.
class StronaController extends CController
{
public function actionIndex()
{
$model = new Uzytkownik;
$wynik = $model::model()->findBySQL('SELECT * FROM uzytkownik WHERE imie=:imie',array(':imie'=>'Jakub'));
for($i=0;$i<count($wynik);$i++)
{
echo count($wynik).' '.$wynik ->imie.'<br>';
}
}
}
Output: 1 Jakub
class Uzytkownik extends CActiveRecord
{
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
It should be
$wynik = $model::model()->findAllBySQL('SELECT * FROM uzytkownik WHERE imie=:imie',array(':imie'=>'Jakub'));
Know the difference between,
findBySql()
AndfindAllBySql()