Are there any specific PHP functions or libraries that can help streamline the process of executing SQL queries entered by users on a webpage?

When allowing users to input SQL queries on a webpage, it is important to sanitize and validate the input to prevent SQL injection attacks. One way to streamline this process is by using prepared statements with parameterized queries, which helps prevent SQL injection by separating the SQL query logic from the user input data.

// Assuming $pdo is your PDO database connection

// User input SQL query
$userQuery = $_POST['query'];

// Prepare the SQL query
$statement = $pdo->prepare($userQuery);

// Execute the prepared statement
$statement->execute();

// Fetch the results
$results = $statement->fetchAll(PDO::FETCH_ASSOC);

// Display the results
foreach ($results as $row) {
    foreach ($row as $key => $value) {
        echo "$key: $value<br>";
    }
    echo "<br>";
}