Skip to content
PHP

PDO API Reference

PHP Data Objects (PDO) — a uniform, object-oriented interface for accessing databases in PHP.

By EZ4Code Team

PDO

Represents a connection between PHP and a database server, providing prepared statements and transactions.

PDO::__construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)

Creates a PDO instance representing a connection to a database via DSN.

Returns: void

PDO::query(string $query, ?int $fetchMode = null): PDOStatement|false

Executes an SQL statement, returning a result set as a PDOStatement. Use for non-parameterized queries.

Returns: PDOStatement|false

PDO::prepare(string $query, array $options = []): PDOStatement|false

Prepares a statement for execution and returns a PDOStatement object. Use for parameterized queries.

Returns: PDOStatement|false

PDO::beginTransaction(): bool

Turns off autocommit mode and begins a transaction. Changes are not committed until commit().

Returns: bool

PDO::commit(): bool

Commits a transaction, making all changes since beginTransaction() permanent.

Returns: bool

PDO::rollBack(): bool

Rolls back the current transaction, undoing all changes made since beginTransaction().

Returns: bool

PDO::lastInsertId(?string $name = null): string|false

Returns the ID of the last inserted row, or the last value from a sequence.

Returns: string|false

More PHP API References