开发者

Return MySQL error from CFQUERY statement

开发者 https://www.devze.com 2023-03-18 16:22 出处:网络
Stupid problem, I have a function that runs a query several times in ablock & reports/emails if/when a query fails. I\'m wondering if/how I can capture the actual MySQL error & return it as pa

Stupid problem, I have a function that runs a query several times in a block & reports/emails if/when a query fails. I'm wondering if/how I can capture the actual MySQL error & return it as part of my email/report.

So far I see no way to do this.

Any thoughts?

-thanks -sean

UPDATE

Thanks Charlie;

I never considered using the cfcatch structure [and truthfully didn't realize it returned so much useful stuff!!]

Unfortunately the host does not allow cfdump so I had to go about it like this:

<cftry>

    <some sql>

<cfcatch type="any">

    <cfscript>
        for (key in cfcatch) {
            try{
                variables.report = variables.report&"<li>"&key&"="&cfcatch[key]&"</li>";
            }
            catch(Any excpt) {
     开发者_JAVA百科           variables.report = variables.report&"<li>"&key&"=??</li>";
            }
        }
    </cfscript>

<cfcatch>

<cftry>


Isn't the native database error returned as part of the cfcatch?

<cftry>
    (some sql here)
    <cfcatch type="any">
        <cfdump var="#cfcatch#" />
    </cfcatch>
</cftry>

If you run that on a page, and intentionally use some invalid SQL, what do you see in the cfdump?

0

精彩评论

暂无评论...
验证码 换一张
取 消