输出JSON是here .when I reload第二次有新的recodes.but当我第一次更新它没有重新编码时
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=$db', "user", "pass");
foreach($dbh->query('SELECT * FROM `jos_jea_towns` LIMIT 0, 500 ') as $row) {
echo '<pre>' . json_encode($row, JSON_PRETTY_PRINT).'</pre>';
}
$insertObject = $dbh->prepare("INSERT INTO `jos_jea_towns` (id, value) VALUES (:id, :value)");
$insertObject->bindParam(':id', $id);
$insertObject->bindParam(':value', $value);
// insert one row
$id = 433;
$value = 'yyy';
$insertObject->execute();
// insert another row with different values
$id = 434;
$value = 'xxx';
$insertObject->execute();
// insert another row with different values
$id = 435;
$value = 'Samitha';
$insertObject->execute();
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>这个PDO准备是如何工作的,或者我的JSON文件有什么问题吗?
发布于 2013-03-31 20:00:12
好的,您是先选择,然后再更新。因此,第一次,在添加记录之前选择,然后添加记录。
在第二次重新加载时,您已经添加了记录(来自上一次迭代),因此将显示插入的记录。
若要求解,请先插入,然后选择之后。这样,您就可以看到您刚才所做的更改。
https://stackoverflow.com/questions/15727127
复制相似问题