Yii Framework Forum: DB Model - Debugging queries. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

DB Model - Debugging queries. Rate Topic: -----

#1 User is offline   kevinkorb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 17-April 09
  • Location:Saint Louis

Posted 21 April 2009 - 03:41 PM

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
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 21 April 2009 - 03:58 PM

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

#3 User is offline   kevinkorb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 17-April 09
  • Location:Saint Louis

Posted 29 April 2009 - 06:48 PM

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.
0

#4 User is offline   will 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 179
  • Joined: 21-March 09

Posted 29 April 2009 - 07:45 PM

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 :)
0

#5 User is offline   kevinkorb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 17-April 09
  • Location:Saint Louis

Posted 29 April 2009 - 07:55 PM

Wow,

Adding the trace is pretty awesome!

Thanks a lot!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users