Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Programming » PHP support » SQL Anywhere PHP extension

 

Creating and running PHP test pages

Create and run several web pages that test whether PHP is set up properly.

Prérequis

You must install PHP. For information about installing PHP, see [external link] http://us2.php.net/install.

Contexte et remarques

This procedure applies to all configurations.

 Task
  1. Create a file in your root web content directory named info.php.

    If you are not sure which directory to use, check your web server's configuration file. In Apache installations, the content directory is often called htdocs. If you are using Mac OS X, the web content directory name may depend on which account you are using:

    • If you are the System Administrator on a Mac OS X system, use /Library/WebServer/Documents.

    • If you are a Mac OS X user, place the file in /Users/your-user-name/Sites/.

  2. Insert the following code into this file:

    <?php phpinfo(); ?>

    The PHP function, phpinfo, generates a page of system setup information. This confirms that your installation of PHP and your web server are working together properly.

  3. Copy the file connect.php from the sdk\php\examples directory to your root web content directory. This confirms that your installation of PHP and SQL Anywhere are working together properly.

  4. Create a file in your root web content directory named sa_test.php and insert the following code into this file:

    <?php
      $conn = sasql_connect( "UID=DBA;PWD=sql" );
      $result = sasql_query( $conn, "SELECT * FROM Employees" );
      sasql_result_all( $result );
      sasql_free_result( $result );
      sasql_disconnect( $conn );
    ?>

    The sa_test page displays the contents of the Employees table.

  5. Start your web server if it is required.

    For example, to start the Apache web server, run the following command from the bin subdirectory of your Apache installation:

    apachectl start
  6. On Linux or Mac OS X, set the SQL Anywhere environment variables using one of the supplied scripts.

    Depending on which shell you are using, enter the appropriate command to source the SQL Anywhere configuration script from your SQL Anywhere installation directory:

    In this shell... ...use this command
    sh, ksh, or bash . /bin32/sa_config.sh
    csh or tcsh source /bin32/sa_config.csh
  7. At a command prompt, run the following command to start the SQL Anywhere sample database (if you have not already done so):

    dbsrv16 "%SQLANYSAMP16%\demo.db"
  8. To test that PHP and your web server are working correctly with SQL Anywhere, access the test pages from a browser that is running on the same computer as the server:

    For this test page... Use this URL...
    info.php http://localhost/info.php
    connect.php http://localhost/connect.php
    sa_test.php http://localhost/sa_test.php

Résultat

The info page displays the output from the phpinfo() call.

The connect page displays the message Connected successfully.

The sa_test page displays the contents of the Employees table.