gpt4 book ai didi

php - 函数不工作 : PHP Fatal error: Call to a member function bind_param() on boolean

转载 作者:行者123 更新时间:2023-11-30 22:13:11 24 4
gpt4 key购买 nike

这是我的函数,我已经在这里坐了好一阵子,试图弄清楚什么不起作用,它在 $stmt2->bind_param:

的行上说
function addDailyTickets() {
global $mysqli,$db_table_prefix;

$stmt = $mysqli->prepare("SELECT
id
FROM ".$db_table_prefix."users
WHERE active=1
");

$stmt->execute();
$stmt->bind_result($id);

while ($stmt->fetch()){
$created_timestamp = time();
$status = "active";
$transaction_id = "daily_".date('n-j-Y');
$game_id = 0;
$ticket_uniqID = uniqid("tick_");

$stmt2 = $mysqli->prepare("INSERT INTO ".$db_table_prefix."tickets (
user_id,
created_timestamp,
status,
transaction_id,
game_id,
ticket_uniqID
)
VALUES (
?,
?,
?,
?,
?,
?
)");
$stmt2->bind_param("iissis", $id, $created_timestamp, $status, $transaction_id, $game_id, $ticket_uniqID);
$stmt2->execute();
}
$stmt->close();
$stmt2->close();
}

如果我放一个 $stmt2->error_list;就在 $stmt2->bind_param 之前,它没有错误地返回。

phpMyAdmin: phpMyAdmin

最佳答案

好吧,感谢@Charlotte Dunois,我想通了,我必须将第一个 mysql 调用放在一个数组中,然后关闭它,然后调用第二个:

function addDailyTickets() {
global $mysqli,$db_table_prefix;

$stmt = $mysqli->prepare("SELECT
id
FROM ".$db_table_prefix."users
WHERE active=1
");

$stmt->execute();
$stmt->bind_result($id);
while ($stmt->fetch()){
$row[] = $id;
}
$stmt->close();

foreach($row as $id){
$created_timestamp = time();
$status = "active";
$transaction_id = "daily_".date('n-j-Y');
$game_id = 0;
$ticket_uniqID = uniqid("tick_");

$stmt2 = $mysqli->prepare("INSERT INTO ".$db_table_prefix."tickets (
user_id,
created_timestamp,
status,
transaction_id,
game_id,
ticket_uniqID
)
VALUES (
?,
?,
?,
?,
?,
?
)");
$stmt2->bind_param("iissis", $id, $created_timestamp, $status, $transaction_id, $game_id, $ticket_uniqID);
$stmt2->execute();
}
$stmt2->close();
}

关于php - 函数不工作 : PHP Fatal error: Call to a member function bind_param() on boolean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39356219/

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