When calling DB::select why do I get a “The connection was reset” message?

前端 未结 2 1824
渐次进展
渐次进展 2021-01-18 06:50

In my Laravel 5.5 application, calls to DB::select which run a select query on a Postgresql database fail without showing any error in the Apache or Laravel error logs and t

相关标签:
2条回答
  • 2021-01-18 06:54

    The tricky part of this has been the browser's stubborn refusal to reveal any form of error message. When that happens, I like to go to the command line and try it, thus eliminating the web server as a variable.

    From chat, we learned that the command line showed the error as expected, but did not gracefully do so: the error was output, and the script was halted. That's a hard crash, one not attributable to the web server.

    With the introduction of \Throwable, the scenarios where PHP dies hard are becoming fewer and farther between. So, in an effort to catch PHP's dying breath, we implemented a register_shutdown_function that pulled error_get_last in an effort to figure out what, if anything, was said just before blowing up.

    This revealed, briefly, the error message in the browser (this time using a different browser). However, this was not repeatable. The insight at this point was caching: composer dump-autoload fixed the problem!

    I suspect what happened is this:

    • Eloquent threw an exception
    • PHP was bubbling that up through Laravel's exception handling classes
    • At some point, PHP attempted to load a class that wasn't in the autoloader
    • PHP crashed hard (this is one of those cases where PHP 7.0 bails)

    By running composer dump-autoload, all the "missing" classes were brought into the autoloader's purview and, when tried again, the correct code sequence happened.

    0 讨论(0)
  • 2021-01-18 07:00

    i think its an Sql query error

     `SELECT * from test()` 
    

    Since () bracket indicates the function so try to use like

     `SELECT * from test` in your query 
    

    Best way in laravel

    Create a model with php artisan make:model Test

    Then use in controller like

         `use App\Test;'
    

    and then to fetch records Test::all(); it will bring all records from database like your requirement SELECT * from Test

    0 讨论(0)
提交回复
热议问题