Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //connect to mysql db
- $db_hostname="localhost";
- $db_username="root";
- $db_password="123kkk";
- $con = mysqli_connect($db_hostname,$db_username,$db_password) or die('Could not connect: ' . mysql_error());
- //connect to the database
- mysqli_select_db($con,"rss_testing");
- $bas = mysqli_select_db($con,"rss_testing");
- //read the json file contents
- $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$');
- //convert json object to php associative array
- $data = json_decode($jsondata, true);
- //get the employee details
- print_r($data);
- foreach ($data as $feed) {
- $cve_id = $feed['cve_id'];
- $summary = $feed['summary'];
- $cvss_score = $feed['cvss_score'];
- $publish_date = $feed['publish_date'];
- $url = $feed['url'];
- $item_exists_sql = "SELECT item_id FROM rss_testing where item_id = '" . $cve_id . "'";
- $item_exists = mysqli_query($con, $bas, $item_exists_sql);
- if(mysqli_num_rows($item_exists)<1)
- {
- $sql = "INSERT INTO rss_testing2(cve_id, summary, cvss_score, publish_date, url)
- VALUES('$cve_id', '$summary', '$cvss_score', '$publish_date', '$url')";
- if (!$con->query($sql)) {
- echo "Table creation failed: (" . $con->errno . ") " . $con->error;
- }
- }
- else
- {
- echo "<font color=blue>Not inserting existing item..</font><br/>";
- }
- } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement