PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

oci_execute> <oci_define_by_name
Last updated: Fri, 05 Sep 2008

view this page in

oci_error

(PHP 5, PECL oci8:1.1-1.2.4)

oci_error最後に見つかったエラーを返す

説明

array oci_error ([ resource $source ] )

最後に見つかったエラーを返します。

パラメータ

source

ほとんどのエラーに対応するため、 パラメータは適当なリソースハンドルを指定可能。 oci_connect()oci_new_connect() あるいは oci_pconnect() での接続エラーの場合、 パラメータを渡さない。

返り値

もしエラーが見つからない場合、oci_error()FALSE を返す。 oci_error() はエラーを連想配列として返す。 この配列には、Oracle エラーコード code や Oracle エラー文字列 message が含まれる。

変更履歴

バージョン 説明
4.3 エラーの場所と原因となった SQL テキストを示すため、 offsetsqltext も返される配列に含まれる。

例1 接続エラー後、Oracle エラーメッセージを表示する

$conn = @oci_connect("scott", "tiger", "mydb");
if (!$conn) {
  $e = oci_error();   // oci_connect のエラーの場合、ハンドルを渡さない
  echo htmlentities($e['message']);
}

例2 パースエラー後、Oracle エラーメッセージを表示する

$stmt = @oci_parse($conn, "select ' from dual");  // クオートが間違っている事に注意
if (!$stmt) {
  $e = oci_error($conn);  // oci_parse のエラーの場合、接続ハンドルを渡す
  echo htmlentities($e['message']);
}

例3 実行エラー後、 Oracle エラーメッセージと問題となった文を表示する

$r = oci_execute($stmt);
if (!$r) {
  $e = oci_error($stmt); // oci_execute のエラーの場合、ステートメントハンドルを渡す
  echo htmlentities($e['message']);
  echo "<pre>";
  echo htmlentities($e['sqltext']);
  printf("\n%".($e['offset']+1)."s", "^");
  echo "</pre>";
}

注意

注意: PHP バージョン 5.0.0 以前では、代わりに ocierror() を使用しなければなりません。 まだこの名前を使用することができ、下位互換性のため oci_error() への別名として残されていますが、 推奨されません。



add a note add a note User Contributed Notes
oci_error
bjanetzki at mpmail.net
02-Nov-2004 05:32
The second example (Displaying the Oracle error message after a parsing error) is wrong.
This example works for me:

$stmt = @oci_parse($conn, "select ' from dual");  // note mismatched quote
if (!$stmt) {
  $e = oci_error($conn);  // For oci_parse errors pass the connection handle
  echo htmlentities($e['message']);
}

oci_execute> <oci_define_by_name
Last updated: Fri, 05 Sep 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites