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

SQL Anywhere 12.0.1 » SQL Anywhere Server - Programming » PHP support » SQL Anywhere PHP extension » Writing PHP scripts


Database connections

To make a connection to a database, pass a standard SQL Anywhere connection string to the database server as a parameter to the sasql_connect function. 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.

The source code for this example is contained in your SQL Anywhere installation in a file called connect.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 );

This script attempts to make a connection to a database on a local server. For this code to succeed, the SQL Anywhere sample database or one with identical credentials must be started on a local server.