2017-05-12 19 views
2

私はウェブサイトで働いていて、先月うまくいきました。突然昨日クラッシュしてWrong COM_STMT_PREPARE response size. Received 7と言います。Laravel 5.4は間違ったCOM_STMT_PREPARE応答サイズを返します

enter image description here

これは、コントローラでの私のコードです:

public function newsFeed() 
{ 
    // get all data needed for the news page 

    try{ 

     $news = DB::SELECT("SELECT 
           n.newId 
           ,n.title_en 
           ,n.title_es 
           ,n.description_en 
           ,n.description_es 
           ,n.newMainImg 
           ,n.tags 
           ,DATE_FORMAT(n.createDate, '%b - %e - %Y') as publishDate_en 
           ,DATE_FORMAT(n.createDate, '%e - %b - %Y') as publishDate_es 
           ,concat(u.firstName,' ',u.lastName) as author 
          FROM NEWS n 
           inner join USERS u 
             on u.userId = n.author 
            and u.statusId = 1 
          order by n.createDate desc limit 20"); 


     $favorites = DB::SELECT("SELECT 
            n.newId 
            ,n.title_en 
            ,n.title_es 
            ,n.newMainImg 
           FROM 
            NEWS n 
           WHERE viewsCount > 0 
            and viewsCount is not null 
           order by viewsCount desc limit 6"); 


     $data = array(
      'news' => $news, 
      'favorites' => $favorites 
     ); 

     return view('news/newsFeed')->with('data', $data); 

    }catch(Exception $exc){ 

     echo $exc->getMessage(); 
    }  

} 

私はどんな解決策を見つけていません。どんな助けでも大歓迎です。

UPDATE

それは、サーバが000webhostであることができます場合、私は多くの人が同じ問題を抱えていることを見てきました。

protected function run($query, $bindings, Closure $callback) 
{ 
    $this->reconnectIfMissingConnection(); 

    $start = microtime(true); 

    // Here we will run this query. If an exception occurs we'll determine if it was 
    // caused by a connection that has been lost. If that is the cause, we'll try 
    // to re-establish connection and re-run the query with a fresh connection. 
    try { 
     $result = $this->runQueryCallback($query, $bindings, $callback); 
    } catch (QueryException $e) { 
     $result = $this->handleQueryException(
      $e, $query, $bindings, $callback 
     ); 
    } 

    // Once we have run the query we will calculate the time that it took to run and 
    // then log the query, bindings, and execution time so we will report them on 
    // the event that the developer needs them. We'll log time in milliseconds. 
    $this->logQuery(
     $query, $bindings, $this->getElapsedTime($start) 
    ); 

    return $result; 
} 

protected function runQueryCallback($query, $bindings, Closure $callback) 
{ 
    // To execute the statement, we'll simply call the callback, which will actually 
    // run the SQL against the PDO connection. Then we can calculate the time it 
    // took to execute and log the query SQL, bindings and time in our memory. 
    try { 
     $result = $callback($query, $bindings); 
    } 

    // If an exception occurs when attempting to run a query, we'll format the error 
    // message to include the bindings with SQL, which will make this exception a 
    // lot more helpful to the developer instead of just the database's errors. 
    catch (Exception $e) { 
     throw new QueryException(
      $query, $this->prepareBindings($bindings), $e 
     ); 
    } 

    return $result; 
} 

答えて

18

この問題は、PDO属性PDO::ATTR_EMULATE_PREPARESをtrueに設定することで解決しました。 config/database.phpのデータベース接続にオプションを追加することができます。

'mysql' => [ 
    'driver' => 'mysql', 
    'host' => env('DB_HOST', 'localhost'), 
    //....... 
    'options' => [PDO::ATTR_EMULATE_PREPARES => true,] 
], 
+0

うわー!!本当にありがとう、本当にありがとう! – Disturb

+0

パーフェクト。ありがとう – Ja22

0

UPDATE 2

エラーは、問題はこれがその周りのコードである647

Connection.phpラインであると言いますどこに行っても研究した後、私はその問題は共有ホスティングのデータベースエンジンにあるのだろうか、おそらく権限か何かであることを否定しているので、私が見つけた解決策は別のサービスでデータベースを作成することでした。私はsql9.freemysqlhosting.netを使用し、これまでのところうまく動作しています。

関連する問題