Lỗi sqlstate 42s02 base table or view not found 1146 năm 2024

PDO offers you a choice of 3 different error handling strategies, to fit your style of application development.

  • PDO::ERRMODE_SILENT Prior to PHP 8.0.0, this was the default mode. PDO will simply set the error code for you to inspect using the PDO::errorCode() andPDO::errorInfo() methods on both the statement and database objects; if the error resulted from a call on a statement object, you would invoke thePDOStatement::errorCode() orPDOStatement::errorInfo() method on that object. If the error resulted from a call on the database object, you would invoke those methods on the database object instead.
  • PDO::ERRMODE_WARNING In addition to setting the error code, PDO will emit a traditional E_WARNING message. This setting is useful during debugging/testing, if you just want to see what problems occurred without interrupting the flow of the application.

PDO::ERRMODE_EXCEPTION

As of PHP 8.0.0, this is the default mode. In addition to setting the error code, PDO will throw aPDOException and set its properties to reflect the error code and error information. This setting is also useful during debugging, as it will effectively "blow up" the script at the point of the error, very quickly pointing a finger at potential problem areas in your code (remember: transactions are automatically rolled back if the exception causes the script to terminate).

Exception mode is also useful because you can structure your error handling more clearly than with traditional PHP-style warnings, and with less code/nesting than by running in silent mode and explicitly checking the return value of each database call.

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'restaurent.sessions' doesn't exist (SQL: select * from sessions`where `id \= Qivf2Trpe45sYfbLci9TzcfKNsIKBZOWH2vKTbbv limit 1)

  • laravel

asked Sep 27, 2022 at 9:49

Lỗi sqlstate 42s02 base table or view not found 1146 năm 2024

4

  • The referenced table does not exist in your database, so; 1) do you have a migration for that table, 2) have you performed a migration (php artisan migrate)? Sep 27, 2022 at 9:54

Sometimes, it gets all values of .env files from its generated cache. On that scenario, simply run the following command to remove the cache for .env. php artisan config:clear