Laravel 5.4 给出了错误的 COM_STMT_PREPARE 响应大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43938610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.4 gives Wrong COM_STMT_PREPARE response size
提问by Disturb
I'm working on a website and it worked fine the past month, suddenly yesterday it crashed and says Wrong COM_STMT_PREPARE response size. Received 7
.
我正在开发一个网站,过去一个月它运行良好,昨天突然崩溃并显示Wrong COM_STMT_PREPARE response size. Received 7
.
This is my code in the controller:
这是我在控制器中的代码:
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();
}
}
I haven't found any solution. Any help would be greatly appreciated.
我还没有找到任何解决方案。任何帮助将不胜感激。
UPDATE:
更新:
If it helps the server is in 000webhost, I've seen that many people is having the same issue.
如果它有助于服务器位于 000webhost,我已经看到很多人都遇到了同样的问题。
UPDATE 2
更新 2
The error says the problem is in Connection.php line 647
错误说问题出在 Connection.php 行 647
This is the code around that:
这是周围的代码:
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;
}
and
和
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;
}
回答by AwledOmara
i solved this issue by setting the PDO attribute PDO::ATTR_EMULATE_PREPARES
to true. you can add an option to your Database Connection under config/database.php.
我通过将 PDO 属性设置PDO::ATTR_EMULATE_PREPARES
为 true解决了这个问题。您可以在 config/database.php 下为您的数据库连接添加一个选项。
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
//.......
'options' => [PDO::ATTR_EMULATE_PREPARES => true,]
],