【发布时间】:2011-03-07 05:11:31
【问题描述】:
我知道我必须在此处包含 mysql_errno y mysql_error 而不是“查询失败”,我尝试使用 $results 作为参数,但我还没有找到方法。
如果有人可以帮助我,谢谢:
static function execSQl2($query)
{
/*
Execute a SQL query on the database
passing the tablename and the sql query.
Returns the LAST_INSERT_ID
*/
$db = null;
$lastid = null;
//echo "query is $query";
try
{
$db = Model::getConnection();
$results = $db->query($query);
if(!$results) {
throw new Exception('Query failed', EX_QUERY_FAILED);
}
$lastid = $db->insert_id;
}
catch(Exception $e)
{
/* errors are handled higher in the
object hierarchy
*/
throw $e;
}
Model::closeConnection($db);
return $lastid;
}
【问题讨论】:
-
看起来您正在使用某种框架。您应该查看它的文档,了解正在使用的数据库类如何报告错误。
标签: php mysql exception-handling