【发布时间】:2011-06-29 23:48:06
【问题描述】:
我正在运行一些代码并且我没有收到任何错误,但该行也没有被删除......所以我有点困惑。所以我检查了代码并发现我的查询有问题,但同时它并没有为我的 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);
}
}
}
【问题讨论】:
-
有什么问题?你能提供实际的错误信息吗?当您直接在 mysql 控制台中尝试查询时会发生什么?
-
你能试试
mysql_error($dblink)吗? -
别告诉我问题出在
DELET... -
@Pekka
mysql_error()不带参数假定最近执行的 mysql 函数,因此它应该在没有它的情况下工作。 -
@ring0:他特别指出'所以我检查了代码并发现我的查询有问题'。他知道查询是错误的。他想知道为什么 if 语句中的代码没有运行。