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 サーバ プログラミング » PHP サポート » SQL Anywhere PHP 拡張 » PHP スクリプトの開発

 

PHP を使用してデータベースに接続する方法

データベースに接続するには、標準の SQL Anywhere 接続文字列を sasql_connect 関数のパラメータとしてデータベースサーバに渡します。<?php と ?> のタグは、この間のコードを PHP が実行し、そのコードを PHP 出力に置き換えることを Web サーバに指定します。

この例のソースコードは、SQL Anywhere インストール環境の connect.php というファイルにあります。

<?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 );
  }?>

このスクリプトは、ローカルサーバでデータベースに接続しようとします。このコードを正常に実行するには、SQL Anywhere サンプルデータベースまたは同じクレデンシャルを持つデータベースがローカルサーバで実行されている必要があります。