这是我的功能,我一直在这里坐下来试图找出什么不起作用,它说它在$ 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之前,它返回时没有错误。
答案 0 :(得分:0)
好的,感谢@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();
}