# Connect to Managed ClickHouse® with PHP


Learn how to connect to your Managed ClickHouse® service with PHP using the PHP ClickHouse client and the HTTPS port.

## Prerequisites

-   [PHP 7.4 or later](https://www.php.net/downloads)
-   `smi2/phpclickhouse` library
-   [Composer](https://getcomposer.org/)

> [!TIP]
> You can install `smi2/phpclickhouse` with the following command:
>
> ```bash
> composer require smi2/phpclickhouse
> ```
>
> or
>
> ```bash
> php composer.phar require smi2/phpclickhouse
> ```

## Identify connection information

To run the code for connecting to your service, first identify values of
the following variables:

| Variable   | Description                               |
|------------|-------------------------------------------|
| `https`    | Required to be set to `true`              |
| `host`     | `Host` for the ClickHouse connection      |
| `port`     | `Port` for the ClickHouse connection      |
| `username` | `User` for the ClickHouse connection      |
| `password` | `Password` for the ClickHouse connection  |
| `database` | `Database Name` in the ClickHouse service |

## Connect to the service

Replace the placeholders in the code with meaningful information on your
service connection and run the code.

```php
<?php
    require_once 'vendor/autoload.php';
    $db = new ClickHouseDB\Client([
        'https' => true,
        'host' => 'HOSTNAME',
        'port' => 'HTTPS_PORT',
        'username' => 'USERNAME',
        'password' => 'PASSWORD'
    ]);
    $db->database('DATABASE');
    $response = $db->select('SELECT 1');
    print_r($response->rows());
```

Now you have your service connection set up and you can proceed to
[uploading data into your database](/product/dbaas/service-specific/clickhouse/quick-start/#load-a-dataset).

## Related pages

- [Connect with the ClickHouse client](/product/dbaas/service-specific/clickhouse/how-to/connect-with-clickhouse-cli/)
- [Connect to Managed ClickHouse®](/product/dbaas/service-specific/clickhouse/how-to/list-connect-to-service/)

