Creating a PHP Object

Install PHP and create a PHP script before installing the new PHP object into the SAP Sybase IQ database.

Prerequisites
Task
  1. Locate the php.ini file for your PHP installation, and open it in a text editor. Locate the line that specifies the location of the extension_dir directory. If extension_dir is not set to any specific directory, it is a good idea to set it to point to an isolated directory for better system security.
  2. Copy the desired external environment PHP module from the SAP Sybase IQ installation directory to your PHP installation directory. Change the x.y to reflect the version you have selected.
    cp $SQLANY12/bin32/php-5.x.y_sqlanywhere_extenv12.so
      php-dir/ext
  3. Add the following line to the Dynamic Extensions section of the php.ini file to load the external environment PHP module automatically. Change the x.y to reflect the version you have selected.
    extension=php-5.x.y_sqlanywhere_extenv12.so

    Save and close php.ini.

  4. Make sure that you have also installed the SQL Anywhere PHP driver from the SAP Sybase IQ installation directory into your PHP extensions directory. This file name follows the pattern php-5.x.y_sqlanywhere.so where x and y are the version numbers.
  5. Verify the database server can locate and start the PHP executable:
    ALTER EXTERNAL ENVIRONMENT PHP 
      LOCATION 'php-path';
  6. Write your PHP script. The <?php and ?> tags tell the web server that it should let PHP execute the code that lies between them and replace it with the PHP output. This connect.php example attempts to make a connection to a database on a local server:
    <?php
      # Connect using the default user ID and password
      $conn = sasql_connect( "UID=DBA;PWD=sql" );
      if( ! $conn ) {
          echo "Connection failed\n";
      } else {
          echo "Connected successfully\n";
          sasql_close( $conn );
      }?>
Related tasks
Installing a PHP Object
Updating a PHP Object
Deleting a PHP Object
Viewing or Modifying PHP Object Properties
Testing the Configuration of a PHP External Environment
Viewing or Modifying PHP External Environment Properties
Related reference
PHP External Environment Privilege Summary