Page 1 of 1

[Added] PHP nuGetLastError()

Posted: Mon Mar 20, 2023 9:37 pm
by admin
There's a new function called nuGetLastError(). This function can be used to retrieve error details when running a query with nuRunQuery().

When you run a query with nuRunQuery() and the function returns -1, it means the query was not successful. To retrieve the error details, you can call the nuGetLastError() function. The function returns an object that contains the following properties:

- user: The user who executed the query.
- message: The PDO error message.
- sql: The SQL query that was executed.
- trace: The stack trace for the error.

Here's an example usage:

Code: Select all

$stmt = nuRunQuery('SELECT * FROM table_that_does_not_exist');
if ($stmt === -1) {
  $error = nuGetLastError();
  nuDisplayError($error->message);
}
In this example, this will display the error message that the table does not exist. E.g.:

Code: Select all

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nubuilder4.table_that_does_not' doesn't exist
You can also access the other properties like this:

- $error->user;
- $error->sql;
- $error->trace;