Added sample sqlite database file, added way of inserting data about the books to the database.
This commit is contained in:
BIN
data.sample.db
Normal file
BIN
data.sample.db
Normal file
Binary file not shown.
25
packt.php
25
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user