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 サーバー プログラミング » PHP サポート » SQL Anywhere 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 サンプルデータベースまたは同じクレデンシャルを持つデータベースがローカルサーバーで実行されている必要があります。