query() and PDOStatement

PDO::query() directly runs an SQL query with no variable parameter and returns a PDOStatement object, whose rows you read with fetch or fetchAll. It is only suitable for queries where no part comes from the user; otherwise, use a prepared statement.

Example

$stmt = $pdo->query('SELECT id, nom FROM produits');

Related concepts

The whole glossary