我正在使用 PHP 和 PDO 将 API 的结果插入 mysql DB (innodb)。这是我的代码:
$insertbrewery = $db->prepare('insert into breweries values(DEFAULT, :api_id, :name, :city, :state, DEFAULT)');
foreach ($data as $result) {
$insertbrewery->bindParam('api_id', $id);
$insertbrewery->bindParam('name', $result[brewery][name]);
$insertbrewery->bindParam('city', $result[brewery][locality]);
$insertbrewery->bindParam('state', $result[brewery][region]);
$insertbrewery->execute();
if ($insertbrewery) {
echo $insertbrewery->rowcount()." breweries successfully submitted.<br />";
} else {
echo "An error occurred with submitting the post to the database. Sorry.";
}
}