There is a parser script in curl, as well as a script that creates a database and writes sparse data to this database. How to make sure that each time the script is run, the sparse data is not written to the new table, but updated instead of the old data? I know that there is an UPDATE function. But I do not understand how to apply it. Here is an example script:
<?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 ) )
?>