Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2. //connect to mysql db
  3. $db_hostname="localhost";
  4. $db_username="root";
  5. $db_password="123kkk";
  6. $con = mysqli_connect($db_hostname,$db_username,$db_password) or die('Could not connect: ' . mysql_error());
  7. //connect to the database
  8. mysqli_select_db($con,"rss_testing");
  9. $bas = mysqli_select_db($con,"rss_testing");
  10. //read the json file contents
  11. $jsondata = file_get_contents('http://www.cvedetails.com/json-feed.php?numrows=10&vendor_id=14&product_id=17&version_id=0&hasexp=0&opec=0&opov=0&opcsrf=0&opfileinc=0&opgpriv=0&opsqli=0&opx$');
  12. //convert json object to php associative array
  13. $data = json_decode($jsondata, true);
  14. //get the employee details
  15. print_r($data);
  16. foreach ($data as $feed) {
  17. $cve_id = $feed['cve_id'];
  18. $summary = $feed['summary'];
  19. $cvss_score = $feed['cvss_score'];
  20. $publish_date = $feed['publish_date'];
  21. $url = $feed['url'];
  22. $item_exists_sql = "SELECT item_id FROM rss_testing where item_id = '" . $cve_id . "'";
  23.         $item_exists = mysqli_query($con, $bas, $item_exists_sql);
  24.         if(mysqli_num_rows($item_exists)<1)
  25.         {
  26.             $sql = "INSERT INTO rss_testing2(cve_id, summary, cvss_score, publish_date, url)
  27.                                VALUES('$cve_id', '$summary', '$cvss_score',  '$publish_date', '$url')";
  28.                        
  29.                 if (!$con->query($sql)) {
  30.     echo "Table creation failed: (" . $con->errno . ") " . $con->error;
  31. }
  32.         }
  33.         else
  34.         {
  35.             echo "<font color=blue>Not inserting existing item..</font><br/>";
  36.         }
  37.  
  38.  
  39.  
  40.  
  41. } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement