Connecting to SQream Using PHP

Overview

PHP is an open source scripting language that executes scripts on servers. The Connect to PHP page explains how to connect to a SQream cluster, and describes the following:

Installing PHP

To install PHP:

  1. Download the JDBC driver installer from the SQream Drivers page.

  2. Create a DSN.

  3. Install the uODBC extension for your PHP installation.

    For more information, navigate to PHP Documentation and see the topic menu on the right side of the page.

Configuring PHP

You can configure PHP in one of the following ways:

  • When compiling, configure PHP to enable uODBC using ./configure --with-pdo-odbc=unixODBC,/usr/local.

  • Install php-odbc and php-pdo along with PHP using your distribution package manager. SQream recommends a minimum of version 7.1 for the best results.

Note

PHP’s string size limitations truncates fetched text, which you can override by doing one of the following:

  • Increasing the php.ini default setting, such as the odbc.defaultlrl to 10000.

  • Setting the size limitation in your code before making your connection using ini_set(“odbc.defaultlrl”, “10000”);.

  • Setting the size limitation in your code before fetchng your result using odbc_longreadlen($result, “10000”);.

Operating PHP

After configuring PHP, you can test your connection.

To test your connection:

  1. Create a test connection file using the correct parameters for your SQream installation, as shown below:

     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
    ?> 
    

    The following is an example of a valid DSN line:

    $dsn = "odbc:Driver={SqreamODBCDriver};Server=192.168.0.5;Port=5000;Database=master;User=rhendricks;Password=super_secret;Service=sqream";
    
  2. Run the PHP file either directly with PHP (php test.php) or through a browser.

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