// Connecting to database $conn = new mysqli("localhost", "username", "password", "database"); // Query to retrieve all items $sql = "SELECT * FROM items"; // Use the query to retrieve data from the database $result = $conn->query($sql); // Loop through the result set and display each item if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo $row["item_name"] . "
"; } }
// Connecting to database $conn = new PDO('mysql:host=localhost;dbname=myDatabase', 'myUsername', 'myPassword'); // Query to retrieve a specific item with a wildcard in the name $sql = "SELECT * FROM items WHERE item_name LIKE '%book%'"; // Use the query to retrieve data from the database $stmt = $conn->prepare($sql); $stmt->execute(); // Loop through the result set and display each item while ($row = $stmt->fetch()) { echo $row["item_name"] . "This code uses PDO library to retrieve a specific item from a table called "items" in a database. It uses a wildcard in the query to search for any item with the word "book" in its name. The result set is then looped through to display each item.
"; }