mysql - Mysql - ErrorException: 发送 QUERY 数据包时出错。PID=6865
问题描述
在 laravel 中创建表时出现以下错误错误-
表创建语法 -
$sql = 'CREATE TABLE `temp_mobile_03b1effe4c12` (
`id` bigint(20) unsigned NOT NULL,
`mobile` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`operator` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`circle` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`country` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
KEY `temp_mobile_03b1effe4c12_id_index` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
DB::connection()->getpdo()->exec($sql);
错误 -
[2019-01-08 15:18:38] local.ERROR: ErrorException: Error while sending QUERY packet. PID=6865 in /var/www/html/listmanager/deploy/releases/20190107104605/app/Jobs/UpdateBulkListSubscribers.php:303
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Error while sen...', '/var/www/html/l...', 303, Array)
#1 /var/www/html/listmanager/deploy/releases/20190107104605/app/Jobs/UpdateBulkListSubscribers.php(303): PDO->exec('CREATE TABLE t...')
#2 /var/www/html/listmanager/deploy/releases/20190107104605/app/Jobs/UpdateBulkListSubscribers.php(264): App\Jobs\UpdateBulkListSubscribers::createTempTable('temp_mobile_00d...', Array, Array)
#3 /var/www/html/listmanager/deploy/releases/20190107104605/app/Jobs/UpdateBulkListSubscribers.php(227): App\Jobs\UpdateBulkListSubscribers->updateMobileInfo()
解决方案
对于 Laravel :运行一般语句 一些数据库语句不返回任何值。对于这些类型的操作,您可以使用 DB 上的语句方法。试试下面的语法
DB::statement($sql);
例如:
DB::statement('drop table users');
推荐阅读
- android - 为什么这里用红色突出显示 -
- amazon-cognito - 当每秒请求超过一定限制时,我们如何获得警告。(Cognito AWS 的配额)
- python - 如何用新列表永久替换列表?
- bash - 在bash中获取最后执行的命令
- c# - Azure WebJobs SDK TimerTrigger 函数未运行
- python - 执行合并后在数据框中创建新列
- ocaml - 沙丘中 package.opam 文件的目的是什么?
- python - 如何摆脱 Python 中的 BeautifulSoup 错误
- android-studio - 片段的嵌套滚动视图
- javascript - Wordpress 如何使用简码从 localStorage 获取值