English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

php odbc_errormsg() function usage and example

PHP ODBC Reference Manual

The odbc_errormsg() function retrieves the last error message.

Syntax

string odbc_errormsg ([ resource $connection_id ] )

Definition and Usage

It is used to get the last error message

Return Value

If connection_id is specified, it returns the last status of that connection; otherwise, it returns the last status of any connection.
This function returns a meaningful value only when the last ODBC query fails (i.e., odbc_exec() returns false).

Parameter

NumberParameters and Description
1

connection_id

It contains information about the connection ID

Example

Try the following example

<?php
   {
      $input_ID = odbc_connect("DSN", "user_id", "pass_id");
      $sql = "SELECT ProductName, UnitPrice FROM WrongTable";
      
      if (!$result = @odbc_exec($input_ID, $sql)) {
         echo "Query error! ODBC error: ", odbc_errormsg();
      } else {
         while (odbc_fetch_row($result)) {
            echo odbc_result($result, "ProductName"), "\n";
         }
      }
   }
?>

PHP ODBC Reference Manual