Yii rocks! Sql beginners question

Hi all,

I’m Gerd a dutch programmer (mainly php and shell)

Recently i started ussing Yii and i must say: Wow what a great framework. Good work!

I think i get the yii basics and dont have any issues with simple apps in yii.

The questions i have is this:

  1. How do i count the numbers of rows in my database table , for example

Select count(*) as viewed from mytabel WHERE viewed=‘Y’

How do i do this with yii? i already got my database model up.

  1. I got a pretty large database with lots of tabels. do i really need to make a model for each tabel or can i make one for an entire database at once?





Each model corresponds to a single database table. You can generate all models at once using Gii model generator. Just type "*" in "Table Name" field.

1 Your first question is answered here: http://www.yiiframework.com/doc/guide/1.1/en/database.arr#statistical-query

2 I think is better to do so when updating individual data table but, you can create views and use those models only for display or reporting. Making just one Model to the whole database? how can you do that?

thanks for the quick responds guys.

i gues having a model for each tabel is important to make relations etc.

Will digg into it the next phew days.

Gerd, you might already now about Gii. If not take a look into it to create models, if needed crud too