Connecting with PHP

You can use PHP to interact with a SQream DB cluster.

This tutorial is a guide that will show you how to connect a PHP application to SQream DB.

Prerequisites

  1. Install the SQream DB ODBC driver for Linux and create a DSN.
  2. Install the uODBC extension for your PHP installation. To configure PHP to enable uODBC, configure it with ./configure --with-pdo-odbc=unixODBC,/usr/local when compiling php or install php-odbc and php-pdo along with php (version 7.1 minimum for best results) using your distribution package manager.

Testing the connection

  1. Create a test connection file. Be sure to use the correct parameters for your SQream DB installation.

    Download this PHP example connection file .

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    <?php // Construct a DSN connection string
    $dsn  = "SqreamODBC"; // Create a connection
    $conn = odbc_connect($dsn, '', '');
    if (!($conn)) {
        echo "Connection to SQream DB via ODBC failed: " . odbc_errormsg($conn);
    }
    $sql = "SELECT show_version()"; // Execute the query
    $rs  = odbc_exec($conn, $sql);
    while (odbc_fetch_row($rs)) {
        for ($i = 1; $i <= odbc_num_fields($rs); $i++) {
            echo "Result is " . odbc_result($rs, $i);
        }
    }
    echo "\n"; 
    odbc_close($conn); // Finally, close the connection
    ?> 
    

    Tip

    An example of a valid DSN line is:

    $dsn = "odbc:Driver={SqreamODBCDriver};Server=192.168.0.5;Port=5000;Database=master;User=rhendricks;Password=super_secret;Service=sqream";
    

    For more information about supported DSN parameters, see ODBC DSN Parameters.

  2. Run the PHP file either directly with PHP (php test.php) or through a browser.