From ea3c59ff860930a548ae58debcd28fd66984c3e3 Mon Sep 17 00:00:00 2001 From: krzysiej Date: Fri, 13 Apr 2018 08:31:22 +0200 Subject: [PATCH] Added sample sqlite database file, added way of inserting data about the books to the database. --- data.sample.db | Bin 0 -> 12288 bytes packt.php | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 data.sample.db diff --git a/data.sample.db b/data.sample.db new file mode 100644 index 0000000000000000000000000000000000000000..6daf9b43388bc370aa1601ecd3c5b16add7c039e GIT binary patch literal 12288 zcmeI#&rZTH90%|Yj0O^k9thVSArLRVfRikSI0nw4;>B&O%*JiS{n2uu`r@Wy-00Izz00bZa0SG_<0uX?}&In9v`<;GYo9CV%vFtgL2h4|zJr^ul zY=`xsZRn0c9sS%i=+?X4#EaQLX7=81wS!K(t$iG?Yx+VwsjIe;?W#vE?KT@O58TGc za*PYZrq;xv*32~N)E

drmKnIn`&*WMs+ov0*s_nUVaJq9$^lN6c+F#@+fop83g7 zZ8gv1u$nE>s0sovXRE@Gc=pKTe!eRtMeMUwELUF0vW-$Hd*SSLD2gQCeD38u32(fp zkQod0+D=i<{K009U<00Izz00bZa0SG_<0;RwgS7(Y{ literal 0 HcmV?d00001 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);