function getProductById($productId) { $dbConnection = new PDO('mysql:host=localhost;dbname=ecommerce', 'username', 'password'); $query = $dbConnection->prepare('SELECT * FROM products WHERE id = :productId'); $query->bindParam(':productId', $productId, PDO::PARAM_INT); $query->execute(); $productData = $query->fetch(PDO::FETCH_ASSOC); return $productData; }In this example, we first connect to a MySQL database and prepare a SQL query that selects a single product by its ID. We then bind the ID parameter to the query, execute it, and fetch the resulting row of product data using the PDO::FETCH_ASSOC fetch mode. Finally, we return the product data as an associative array. The package library used in this code example is the PDO extension for PHP, which provides an object-oriented interface for working with databases.