What is the correct way to combine a page title and a keyword from a database in PHP?

When combining a page title and a keyword from a database in PHP, it is important to properly sanitize and escape the data to prevent SQL injection attacks. One way to achieve this is by using prepared statements with placeholders to safely insert the data into the SQL query.

// Assuming $pageTitle and $keyword are variables containing the page title and keyword from the database
// Establish a database connection
$pdo = new PDO("mysql:host=localhost;dbname=your_database", "username", "password");

// Prepare the SQL query with a placeholder for the keyword
$stmt = $pdo->prepare("SELECT * FROM your_table WHERE title = :title AND keyword = :keyword");

// Bind the values to the placeholders
$stmt->bindParam(':title', $pageTitle);
$stmt->bindParam(':keyword', $keyword);

// Execute the query
$stmt->execute();