diff --git a/data.sample.db b/data.sample.db new file mode 100644 index 0000000..6daf9b4 Binary files /dev/null and b/data.sample.db differ diff --git a/packt.php b/packt.php index 3128439..7053c97 100644 --- a/packt.php +++ b/packt.php @@ -115,7 +115,32 @@ foreach ($books as $book) { $bookData['url'] = $book->first('div[class*=product-thumbnail]')->first('a::attr(href)'); $bookData['info'] = getBookInfo($bookData['url']); + + + + $db = new SQLite3('data.db'); + $stmt = $db->prepare('REPLACE INTO book (nid, title, isbn, img, url, datepublished, numberofpages, reviewCount, ratingValue, category, pdf, epub, mobi, code) +VALUES (:nid, :title, :isbn, :img, :url, :datepublished, :numberofpages, :reviewCount, :ratingValue, :category, :pdf, :epub, :mobi, :code)'); + $stmt->bindValue(':nid', $bookData['nid'], SQLITE3_INTEGER); + $stmt->bindValue(':title', $bookData['title'], SQLITE3_TEXT); + $stmt->bindValue(':isbn', $bookData['isbn'], SQLITE3_TEXT); + $stmt->bindValue(':img', $bookData['img'], SQLITE3_TEXT); + $stmt->bindValue(':url', $bookData['url'], SQLITE3_TEXT); + $stmt->bindValue(':datepublished', $bookData['info']['datepublished'], SQLITE3_TEXT); + $stmt->bindValue(':numberofpages', $bookData['info']['numberofpages'], SQLITE3_INTEGER); + $stmt->bindValue(':reviewCount', $bookData['info']['reviewCount'], SQLITE3_INTEGER); + $stmt->bindValue(':ratingValue', (float)$bookData['info']['ratingValue'], SQLITE3_FLOAT); + $stmt->bindValue(':category', $bookData['info']['category'], SQLITE3_TEXT); + $stmt->bindValue(':pdf', $bookData['pdf'], SQLITE3_TEXT); + $stmt->bindValue(':epub', $bookData['epub'], SQLITE3_TEXT); + $stmt->bindValue(':mobi', $bookData['mobi'], SQLITE3_TEXT); + $stmt->bindValue(':code', $bookData['code'], SQLITE3_TEXT); + + $result = $stmt->execute(); + + $booksData[$bookData['nid']] = $bookData; + } print_r($booksData);