在SQlite数据库中更新数据

时间:2017-11-18 07:54:18

标签: php sqlite

curl中有一个解析器脚本,以及一个创建数据库并将稀疏数据写入此数据库的脚本。如何确保每次运行脚本时,稀疏数据不会写入新表,而是更新而不是旧数据?我知道有一个UPDATE函数。但我不明白如何应用它。这是一个示例脚本:

<?php
$___notjson=1;
ini_set('display_errors', 1);
header ('Content-type: text/html; charset=utf-8');
require ('phpQuery.php');

$ch = curl_init('http://allhyipdata.com/hyip/bitcy.biz');
curl_setopt($ch, CURLOPT_USERAGENT, "booyah!");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$allhyipdata = curl_exec($ch);
curl_close($ch);
$doc = phpQuery::newDocument($allhyipdata);
$ssl = $doc->find('.no-padding-bottom tr:eq(1) td:eq(3)')->text();
$ddos = $doc->find('.no-padding-bottom tr:eq(2) td:eq(3)')->text();

echo '<div>SSL:' .$ssl .'</div>';
echo '<div>DDoS:' .$ddos .'</div>';

try {
$db = new PDO('sqlite:bitcy.biz');
$db->exec("CREATE TABLE IF NOT EXISTS `bitcy.biz` (
                        `ssl` VARCHAR,
                        `ddos` VARCHAR
                     );
                  ");
} catch ( PDOException $e ) {
     exit("Ошибка: ".$e->getMessage()."<br>Строка: ".$e->getLine());
}
$db->query("INSERT INTO `bitcy.biz` (ssl, ddos) VALUES ('$ssl', '$ddos')");
$result = $db->query('SELECT * FROM `bitcy.biz`')->fetchAll(PDO::FETCH_ASSOC);
print_r($result); // Array ( [0] => Array (  [ssl]=> $ssl  [ddos]=> $ddos ) )

?>

0 个答案:

没有答案