1 回答

TA貢獻(xiàn)1883條經(jīng)驗(yàn) 獲得超3個(gè)贊
考慮以下:
錯(cuò)誤的原因是您$stmt為SELECTandINSERT語句使用了一個(gè)變量,并且在第一個(gè)INSERT語句之后while ($result = $stmt->fetch(PDO::FETCH_COLUMN)) ...生成了錯(cuò)誤。為INSERT語句使用不同的變量。
該INSERT語句在 中有四個(gè)參數(shù)占位符prepare(),但在 中只有三個(gè)值execute()。
用于PDOStatement::fetchColumn返回一行中的一列。
代碼:
<?php
...
while ($result = $stmt->fetchColumn(0)) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://somegame.com/api/nation/id=$result&key=myapikey");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$nation = curl_exec($ch);
$json = $nation;
$nation = json_decode($nation, true);
$stmt2 = $pdo->prepare("INSERT INTO nation_record(nation_id,as_on,json) VALUES (?,?,?)");
$stmt2->execute([$result, date("Y-m-d"), $json ]);
}
...
?>
- 1 回答
- 0 關(guān)注
- 254 瀏覽
添加回答
舉報(bào)