# PHP (PDO)

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

---
title: PHP (PDO)
latest-operator-version: v26.1.4
latest-console-tag: v3.7.3
latest-connect-version: 4.93.0
latest-redpanda-tag: v26.1.9
docname: connect-to-sql/language-clients/php-pdo
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: connect-to-sql/language-clients/php-pdo.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/sql/pages/connect-to-sql/language-clients/php-pdo.adoc
description: Connect to Redpanda SQL from PHP using PHP Data Objects (PDO).
page-topic-type: how-to
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-05-26"
---

<!-- Source: https://docs.redpanda.com/cloud-data-platform/sql/connect-to-sql/language-clients/php-pdo.md -->

[PHP Data Objects (PDO)](https://www.php.net/manual/en/book.pdo.php) is a PHP extension that provides a consistent interface for accessing databases. Because Redpanda SQL implements the PostgreSQL wire protocol, you can use PDO’s PostgreSQL driver to connect from PHP. This page describes how to use PHP PDO with Redpanda SQL and lists unsupported functions and structures.

## [](#establish-a-sql-connection)Establish a SQL connection

```php
conn = new PDO(
    "pgsql:host=<host>;port=<port>;dbname=<database>",
    "<username>",
    "<password>",
    [
        PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        PDO::ATTR_EMULATE_PREPARES   => true,
    ]);
```

Note that the `PDO::ATTR_EMULATE_PREPARES` attribute is set to `true`, which is required in Redpanda SQL to ensure stability of query execution. Without this attribute setup, you may encounter `prepared statement` errors during queries execution:

```none
    ERROR: prepared statement [...]
```

> 📝 **NOTE**
>
> If you are running Redpanda Cloud, you can append `sslmode=verify-full;sslrootcert=<path-to-ssl-cert>` to the first parameter of `PDO` to ensure full SSL endpoint verification and encryption.

## [](#example-usage)Example usage

This example shows basic query execution, once the connection has been established:

```php
$stmt = $conn->prepare("SELECT :number as num;", [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$stmt->execute(['number' => 1234]);
$res = $stmt->fetchAll();
print_r($res)
```

## [](#unsupported-functions-and-structures)Unsupported functions and structures

The following functions and potentially related structures are not currently supported when working with Redpanda SQL and PHP PDO:

-   `PDO::pgsqlLOBCreate`, `pgsqlLOBOpen` - [Large Objects](https://www.postgresql.org/docs/current/largeobjects.html)

-   `PDO::pgsqlGetPid` - [returning processes ID](https://www.php.net/manual/en/function.pg-get-pid.php)

-   `PDO::pgsqlCopytFromFile`, `PDO::pgsqlCopytFromArray` - [copy from STDIN](https://www.postgresql.org/docs/current/sql-copy.html)

-   `PDO::pgsqlCopytToFile` - [copy to STDIN](https://www.postgresql.org/docs/current/sql-copy.html)

-   `PDO::pgsqlCopytToArray` - [copy to STDOUT](https://www.postgresql.org/docs/current/sql-copy.html)

-   `PDO::pgsqlGetNotify` - [`LISTEN`](https://www.postgresql.org/docs/current/sql-listen.html) and [`NOTIFY`](https://www.postgresql.org/docs/current/sql-notify.html) channel commands

-   `PDO::lastInsertId` - [SEQUENCES](https://www.postgresql.org/docs/current/sql-createsequence.html)

-   `PDO::beginTransaction`, `PDO::inTransaction`, `PDO::commit`, `PDO::rollBack` - [Transactions](https://www.postgresql.org/docs/current/tutorial-transactions.html)

-   `PDOStatement::rowCount` - may return incorrect row counts for some operations