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.

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
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    <?php
    
    // Construct a DSN connection string
    $dsn = "odbc:Driver={SqreamODBCDriver};Server=<server address>;Port=<server port>;Database=<database name>;User=<username>;Password=<password>;Service=sqream";
    
    // 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 ($row = odbc_fetch_object($rs)) 
    {
        echo ($row);
    }
    
    // Finally, close the connection
    odbc_close($conn);
    
    ?>
    

    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.