Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

[Added] PHP nuGetLastError()

Information about updates, news, Code Library
admin
Site Admin
Posts: 2778
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5

[Added] PHP nuGetLastError()

Unread post 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;
Post Reply