For this purpose we will use the popular PHP library FPDF which will enable us to generate the PDF file with the content and ourput format we desire.
Step-1: Get the data from MySQL database into the page
Step-1: Download the FPDF library from fpdf.org
Step-2: Copy the fpdf.php file into your application folder
Step-3: Use the fpdf library like so
Step-1: Download the FPDF library from fpdf.org
Step-2: Copy the fpdf.php file into your application folder
Step-3: Use the fpdf library like so
books.sql
index.php
database.php
1 | <?php class Database { private $host = "localhost"; private $user = "root"; private $password = "root"; private $database = "crud"; function runQuery($sql) { $conn = new mysqli($this->host,$this->user,$this->password,$this->database); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $result = $conn->query($sql); if ($result->num_rows > 0) { while($row = $result->fetch_assoc()) { $resultset[] = $row; } } $conn->close(); if(!empty($resultset)) return $resultset; } } ?> |
No comments:
Post a Comment