0

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 ) )

?>
u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • 1
    English please, if possible! – Akshit Arora Nov 18 '17 at 07:55
  • 1
    Your site is http://ru.stackoverflow.com/ – u_mulder Nov 18 '17 at 07:59
  • Hello. 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: – Aleks Manzur Nov 18 '17 at 07:59
  • Please, __do not__ write comments, [edit] your question. – u_mulder Nov 18 '17 at 08:00
  • Thank you for your help, I found something for myself. And you can make it so that the UPDATE function is executed once every 24 hours. Ie, if you sent a request to add or change an entry in the database file, the next update of the database can be done only tomorrow, after 24 hours for example. I ask you to apologize for the level of my English, all translation is carried out through Google translator – Aleks Manzur Nov 18 '17 at 10:19

0 Answers0