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

SQL Anywhere 10.0.1 » SQL Anywhere Server - Programming » SQL Anywhere PHP API » Running PHP test scripts in your web pages

Running PHP test scripts in your web pages Next Page

Creating PHP test pages

The following instructions apply to all configurations.

To test whether PHP is set up properly, the following procedure describes how to create and run a web page that calls phpinfo. phpinfo is a PHP function that generates a page of system setup information. The output tells you whether PHP is working properly.

For information on installing PHP, see [external link]

To create a PHP information test page
  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:

  2. Insert the following code into this file:

    <? phpinfo() ?>

    Alternatively, once PHP is properly installed and configured, you can also create a test web page by issuing the following command at a command prompt.

    php -I > info.html

    This confirms that your installation of PHP and your web server are working together properly.

  3. To test that PHP and your web server are working correctly with SQL Anywhere:

    1. Copy the file connect.php from your PHP examples directory to your root web content directory.

    2. From a web browser, access the connect.php page.

      The message Connected successfully should appear.

To create the query page that uses the SQL Anywhere PHP module
  1. Create a file containing the following PHP code in your root web content directory named sa_test.php.

  2. Insert the following PHP code into this file:

      $conn = sqlanywhere_connect( "UID=DBA;PWD=sql" );
      $result = sqlanywhere_query( $conn, "SELECT * FROM Employees" );
      sqlanywhere_result_all( $result );
      sqlanywhere_free_result( $result );
      sqlanywhere_disconnect( $conn );