PHPからOracleへの動作確認
接続先のデータベースで、ユーザー「SCOTT」を利用できるようにします。sqlplusで接続も行ってみます。
sqlplus system/<PASSWORD>@//php-test.jp.oracle.com:1521/ORCL SQL*Plus: Release 10.2.0.3.0 - Production on 金 5月 11 04:38:17 2007 Copyright (c) 1982, 2006, Oracle. All Rights Reserved. Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options に接続されました。 SQL>alter user scott account unlock; ユーザーが変更されました。 SQL> alter user scott identified by tiger; ユーザーが変更されました。 SQL> exit Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine optionsとの接続が切断されました。
次に、ユーザー「SCOTT」でログインして確認します。
sqlplus scott/tiger@//php-test.jp.oracle.com:1521/ORCL SQL*Plus: Release 10.2.0.3.0 - Production on 金 5月 11 04:45:32 2007 Copyright (c) 1982, 2006, Oracle. All Rights Reserved. Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options に接続されました。 SQL>exit
サンプルスクリプトを作成します。この例は動作確認のために現在の時間を返すだけのSELECT文を実行しています。
vi /usr/local/apache2/htdocs/ora_test.php <?php $con = oci_connect("scott","tiger","//php-test.jp.oracle.com:1521/ORCL"); //オラクルデータベースへ接続 $sql = "select sysdate from dual"; // 実行するSELECT文 $stmt = oci_parse($con, $sql); // SQL文のパース処理 $results = oci_execute($stmt); // パースしたSQL文を実行し、結果を得る $row = oci_fetch_row($stmt); // 結果を$row配列に取得(1行) echo $row[0] . "\r\n"; // 結果をエコー oci_close($con); // 接続を切断 ?>
コマンドラインで実行してみます。
php ./ora_test.php 07-05-10
日付が表示されるはずです。
同様に、Webブラウザからアクセスして確認してみます。
http://mmatsuza-jp-vm.jp.oracle.com/ora_test.php
終わりに
以上が、PHPモジュールをコンパイルする際に組み込む方法の説明です。これで、PHPを通じてOracle Databaseを利用できるようになりました。
次回ではこの環境を利用して、Oracle Databaseへの様々なデータの入出力を解説します。

