How can you determine the query type using PDOStatement->execute in PHP?

To determine the query type using PDOStatement->execute in PHP, you can use the PDOStatement->queryString property to retrieve the SQL query string that was prepared. You can then analyze this query string to determine the type of query being executed, such as SELECT, INSERT, UPDATE, or DELETE.

// Assume $pdo is your PDO object and $sql is your SQL query string
$stmt = $pdo->prepare($sql);
$stmt->execute();

$queryType = strtoupper(explode(' ', $stmt->queryString)[0]);
echo "The query type is: " . $queryType;