首页 > 解决方案 > 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()

标签: mysqllaravel-5pdo

解决方案


对于 Laravel :运行一般语句 一些数据库语句不返回任何值。对于这些类型的操作,您可以使用 DB 上的语句方法。试试下面的语法

DB::statement($sql);

例如:

DB::statement('drop table users');

推荐阅读