gpt4 book ai didi

php - 数据库连接查询错误

转载 作者:行者123 更新时间:2023-11-29 06:18:26 24 4
gpt4 key购买 nike

查看我的错误日志,我经常收到以下错误:

[01-Mar-2011 04:31:27] exception 'Exception' with message 'Query failed' in /home1/mexautos/public_html/kiubbo/data/model.php:89
Stack trace:
#0 /home1/mexautos/public_html/kiubbo/data/article.php(275): Model::execSQl2('update articles...')
#1 /home1/mexautos/public_html/kiubbo/data/article.php(111): Article->save()
#2 /home1/mexautos/public_html/kiubbo/pages/frontpage.php(21): Article->calculateRanking()
#3 /home1/mexautos/public_html/kiubbo/pages/frontpage.php(27): FrontPage->updateRanking()
#4 /home1/mexautos/public_html/kiubbo/index.php(15): FrontPage->showTopArticles('')
#5 {main}

如果我转到 model.php 文件,我会看到以下内容:

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;
}

有人看到错误吗,或者我应该看看其他地方?

谢谢您并致以问候,卡洛斯

编辑:

这是查询:$lastid = Parent::execSql2($query);

这是上下文:

function save() {

/*
Here we do either a create or
update operation depending
on the value of the id field.
Zero means create, non-zero
update
*/

if(!get_magic_quotes_gpc())
{
$this->title = addslashes($this->title);
$this->description = addslashes($this->description);
}

try
{
$db = parent::getConnection();
if($this->id == 0 )
{
$query = 'insert into articles (modified, username, url, title, description, points )';
$query .= " values ('$this->getModified()', '$this->username', '$this->url', '$this->title', '$this->description', $this->points)";

}
else if($this->id != 0)
{
$query = "update articles set modified = NOW()".", username = '$this->username', url = '$this->url', title = '".$this->title."', description = '".$this->description."', points = $this->points, ranking = $this->ranking where id = $this->id";
}

$lastid = parent::execSql2($query);

if($this->id == 0 )
$this->id = $lastid;

}
catch(Exception $e){
error_log($e);
}
}

问候,卡洛斯

最佳答案

正如 heximal 所说,这可能是您的 SQL 查询中的错误。将正在查询的完整 SQL 复制并粘贴到 PhpMyAdmin 或类似工具中,然后查看出现什么错误(如果有)。通常,问题只是表输入错误或值缺失。当然,如果您需要帮助,也可以在这里发布查询! :D

关于php - 数据库连接查询错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5154189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com