DB Model - Debugging queries.

I'm brand new to the framework, but I find myself a bit hung up with the error messages I get back while issuing mySQL stuff.

i.e.

CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined.

Is there a command I can use to get whatever my DB query would have been for debugging?  Is there anything I'm missing?

Thanks

Could you turn on logging and describe what is the SQL generated?

Ahh, ok I figured it out.

Thanks qiang.

I basically made the query output when I had a query error which definatly helped me out.

I changed line 115 in CDbCommand to:

throw new CDbException(Yii::t('yii','CDbCommand failed to prepare the SQL statement: {error}' . $this->getText(),

Which adds my query to my log.

I'm not sure if this is the best way to handle it, but it really helped me out.  If there is another way I 'should' be doing it please let me know.

I'm trying to really learn the framework, but when I don't really know the best way I find myself hacking through it.

Thanks.

Quote

Ahh, ok I figured it out.

Thanks qiang.

I basically made the query output when I had a query error which definatly helped me out.

I changed line 115 in CDbCommand to:

throw new CDbException(Yii::t('yii','CDbCommand failed to prepare the SQL statement: {error}' . $this->getText(),

Which adds my query to my log.

I'm not sure if this is the best way to handle it, but it really helped me out.  If there is another way I 'should' be doing it please let me know.

I'm trying to really learn the framework, but when I don't really know the best way I find myself hacking through it.

Thanks.

hmm, I think you hit the wrong way, you should never change the framework core code.

What Qiang was referring is to enable log component in config file, here is sample code:

You could find the sql in log by enabling 'CWebLogRoute'.

I wish this helps :)

Wow,

Adding the trace is pretty awesome!

Thanks a lot!