开发者

mysql_error() & mysql_affected_rows() do not work correctly within transaction

开发者 https://www.devze.com 2023-02-13 01:38 出处:网络
I recently asked this question here: Why doesn't this query produce a mysql_error() result? The suggested solution was to use mysql_affected_rows() instead...... however I just got around to tryi

I recently asked this question here: Why doesn't this query produce a mysql_error() result?

The suggested solution was to use mysql_affected_rows() instead...... however I just got around to trying this, but it does the opposite...

If I do this..

    if (mysql_affected_rows() < 1) {
        $etext = 'Problem removing list main entry from database.';
        $log_error = $etext . ' MySQL Error: ' . mysql_error() . '. Query: ' . $query;
        log_site_error($log_error);
        throw new Exception($etext);
    }

...or this:

    if (mysql_affected_rows() < 0) {
        $etext = 'Problem removing list main entry from database.';
        $log_error = $etext . ' MySQL Error: ' . mysql_error() . '. Query: ' . $query;
        log_site_error($log_error);
        throw new Exception($etext);
    }

It ALWAYS goes in the error section, meaning it always THINKS there was a problem. I tried the query that was output to the log file & it works fine. I also completely removed those error checking sections & everything ran fine.... the database rows were deleted as expected.

How can I error check this effectively?

Edit: Strangely enough when I added the DB Resource开发者_运维百科 Connection as a parameter to the mysql_error() call it worked.


I think the problem is that you are not checking the return value of mysql_query. That is the way to test if a query succeeded or failed, not calling mysql_error or mysql_affected_rows.

0

精彩评论

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