Added sample sqlite database file, added way of inserting data about the books to the database.

This commit is contained in:
krzysiej
2018-04-13 08:31:22 +02:00
parent f016f0e4f2
commit ea3c59ff86
2 changed files with 25 additions and 0 deletions

BIN
data.sample.db Normal file

Binary file not shown.

View File

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