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

    For more information, download the sample PHP example connection file shown above.

    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.