example of PHP code that retrieves and displays PDF documents from a database table called books
+1

PHP
php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
// connect to the database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "books_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// prepare and execute the query
$query = "SELECT * FROM books WHERE title LIKE ?";
mysqli_stmt_bind_param($query, 's', $_POST['title']);
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
// fetch and display the data
header("Content-type: application/pdf");
while ($row = mysqli_fetch_assoc($result)) {
echo $row['document'];
}
// close the connection
mysqli_close($conn);
?>
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run