2011-02-18 109 views
0

我正在運行一些代碼&我沒有得到任何錯誤,但行也沒有被刪除....所以我有點困惑。所以我檢查了代碼&發現我的查詢有問題,但同時它不會產生真正的結果給我的mysql_error()測試。爲什麼這個查詢不產生mysql_error()結果?

我使用下面的代碼..

 try { 
      // Start transaction 
      beginTransaction($this->db_connection); 
     } catch (Exception $e) { 
      throw new Exception($e->getMessage()); 
     } 

     try { 

      // Delete main entry 
      $this->removeMainEntry($lid); 

      // Delete list columns 
      $this->removeListColumns($lid); 

      // Commit changes to database 
      commitChanges($this->db_connection); 

     } catch (Exception $e) { 

      try { 
       // Rollback changes 
       rollback($this->db_connection, $e->getMessage()); 
      } catch (Exception $re) { 
       throw new Exception($re->getMessage()); 
      } 

      throw new Exception($e->getMessage());      

     } 

這裏是哪裏出了問題&它不進入mysql_error()部分..

protected function removeMainEntry($lid) { 

    $lid = (int) $lid; 

    // Remove from database 
    $query = "DELET FROM lists WHERE id=" . $lid . " LIMIT 1"; 
    $sql = mysql_query($query, $this->db_connection); 

    if (mysql_error()) { 
     $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); 
    } 

} 

下面是從代碼我使用的那些函數..

if (!function_exists('beginTransaction')) { 

    function beginTransaction($dblink) { 

     $query = "BEGIN"; 
     mysql_query($query, $dblink); 

     if (mysql_error()) { 
      $etext = 'Problem adding new list data to database.'; 
      $log_error = $etext . ' MySQL Error: ' . mysql_error() . '. Query: ' . $query; 
      log_site_error($log_error); 
      throw new Exception($etext);    
     } 

    } 

} 

if (!function_exists('commitChanges')) { 

    function commitChanges($dblink) { 

     $query = "COMMIT"; 
     mysql_query($query, $dblink); 

     if (mysql_error()) { 
      $etext = 'Problem adding new list data to database.'; 
      $log_error = $etext . ' MySQL Error: ' . mysql_error() . '. Query: ' . $query; 
      log_site_error($log_error); 
      throw new Exception($etext);    
     } 

    }  

} 

if (!function_exists('rollback')) { 

    function rollback($dblink, $error = '') { 

     $query = "ROLLBACK"; 
     mysql_query($query, $dblink); 

     if (mysql_error()) { 
      $etext = $error . ' Additionally there was a problem rolling back the changes in the database. Please check the logs.'; 
      $log_error = $etext . ' MySQL Error: ' . mysql_error() . '. Query: ' . $query; 
      log_site_error($log_error); 
      throw new Exception($etext); 
     } 

    } 

} 
+0

什麼問題?你能提供實際的錯誤信息嗎?當您在mysql控制檯中直接嘗試查詢時會發生什麼? – eykanal 2011-02-18 17:28:41

+0

你可以試試`mysql_error($ dblink)`嗎? – 2011-02-18 17:28:52

回答

3

如果您刪除0行,它可能仍然會被視爲一個成功。使用mysql_affected_rows確保你確實做了任何事情。

相關問題