$pdo = new PDO('mysql:host=localhost;dbname=mydatabase;', 'username', 'password'); $sql = "SELECT customers.name, orders.order_date, orders.total_price FROM customers JOIN orders ON customers.id = orders.customer_id WHERE customers.id = :id"; $statement = $pdo->prepare($sql); $statement->execute(['id' => 123]); $results = $statement->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row) { echo $row['name'] . " made an order on " . $row['order_date'] . " for " . $row['total_price'] . "In this example, we're joining the customers and orders tables using the common field `customer_id`. We're also using a parameterized query to avoid SQL injection vulnerabilities. The package library used in this code example is the PDO package, which is a lightweight database access library in PHP that provides a consistent interface for accessing various database management systems.
"; }