gpt4 book ai didi

php - 在循环内关闭插入查询

转载 作者:行者123 更新时间:2023-11-29 00:01:08 25 4
gpt4 key购买 nike

我正在尝试循环插入查询,但我一直收到错误,这似乎与我的 close() 语句有关?

我有以下代码不断返回以下错误:

Fatal error: Call to a member function close() on a non-object in

为了简化问题,我故意删除了 insert_news 查询中的信息 $variables

function check_text($text, $last_id) {
global $ids;
foreach($ids as $id => $teams) {
foreach($teams as $team) {
if(stripos(($text, $team) !== false) {

$teamRelation = $con->prepare("INSERT INTO contain (`team_id`, `news_id`) VALUES (?, ?)");
$teamRelation->bind_param("ii", $id, $last_id);
$teamRelation->execute();

}
}
}

$teamRelation->close();

}

function scrape_afton() {

foreach($afton->find("//section/ul/li") as $afton_element) {

$insert_news = $con->prepare("INSERT INTO news (`title`, `url`, `image_url`, `date`, `news_text`, `website_id`) VALUES (?, ?, ?, ?, ?, 1)");
$insert_news->bind_param("sssss", $afton_title, $afton_link, $afton_img, $afton_datetime, $full_text_dont);
$insert_news->execute();
$afton_last_id = $con->insert_id;

check_text($afton_full_text, $afton_last_id);

}
}

最佳答案

$con 未在函数内定义。我假设它是一个全局的,所以将它添加到你的全局变量中:

全局$ids,$con;

关于php - 在循环内关闭插入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29783335/

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