Symfony SQLSTATE[42000]:语法错误或访问冲突:flush()期间为1064

问题描述 投票:0回答:2

我们使用 Docker 和 Symfony 5.6、PHP 8.0、xcaddy v2.7.3 和 MariaDB 10.3.34 以及 Doctrine。该应用程序分为 cron、caddy、node、php、db、db-backup 和 mailer 容器。

创建任何新实体并尝试将其保存到数据库时会出现此问题。删除实体效果很好。确切的错误消息是:

执行查询时发生异常:SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解在 '?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 附近使用的正确语法。 ?, ?, ?, ?, ?, ?, ?)' 在第 1 行

. It's thrown in 
vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php`

(
开头缺失的
'?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' at line 1
对我来说非常有趣,因为正常的查询可能看起来更像这样:
'INSERT INTO article (id, description, name, deletaed_at) VALUES (?, ?, ?, ?)' 

唉,我很困惑,因为我们没有修改

flush()
并且最近没有进行任何数据库迁移。我们可以顺利连接到数据库(开发和实时)(例如获取数据、删除、PhpStorm 视图)。

最新更改已将 xcaddy 从 2.6.4 更新到 2.72。注意到 2.73 的错误,然后再次注意到 2.6.4 的错误,但它仍然存在。

我不知道它是否相关,但

bin/console doctrine:schema:validate
不返回任何警告或错误。

当使用调试器单步执行该过程时,实体本身及其所有数据都存在。字段和值已正确评估。可以在代码中建立与数据库的连接。

有关

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ...
的所有其他帖子似乎都是手写查询或包含保留的列名称,因此我目前看不到应用他们的解决方案的方法。任何帮助将不胜感激。

编辑:6 月 3 日过去的提交有效,并且 docker compose 构建使用当天的数据与我们当前的主提交一起工作,所以我将继续攀升提交,直到它不再工作。

运行后

composer update
发生了变化

  • vendor/bin/doctrine
    ,
  • vendor/bin/doctrine-dbal
    ,
  • vendor/bin/doctrine-migrations
    ,
  • vendor/bin/path-type-declarations
    ,
  • vendor/bin/php-parse
    ,
  • vendor/bin/simple-phpunit
    ,
  • vendor/bin/var-dump-server
  • vendor/bin/yaml-lint

但是每个文件中唯一的更改是从

    if (
        (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
        || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
    ) {
        include("phpvfscomposer://" . __DIR__ . '/..'.'/doctrine/orm/bin/doctrine');
        exit(0);
    }
}

include __DIR__ . '/..'.'/doctrine/orm/bin/doctrine';

    if (
        (function_exists('stream_get_wrappers') && in_array('phpvfscomposer', stream_get_wrappers(), true))
        || (function_exists('stream_wrapper_register') && stream_wrapper_register('phpvfscomposer', 'Composer\BinProxyWrapper'))
    ) {
        return include("phpvfscomposer://" . __DIR__ . '/..'.'/doctrine/orm/bin/doctrine');
    }
}

return include __DIR__ . '/..'.'/doctrine/orm/bin/doctrine';

编辑: 许多实体都会发生此错误,但设置通常是这样的。谢谢,我会寻找一种方法来获取查询

public function addArticle(Request $request): Response
    {
        $data = json_decode($request->getContent(), null, 512, JSON_THROW_ON_ERROR);
        if (!isset($data->id)) {
            throw new BadRequestException('No id was given');
        }
        $masterArticle = $this->masterArticleRepository->find($data->id);
        if (!$masterArticle) {
            throw $this->createNotFoundException();
        }
        $period = $this->getPeriod($request);
        $periodArticle = new PeriodArticle($masterArticle, $period);
        $this->entityManager->persist($periodArticle);
        $this->entityManager->flush();

        return new JsonResponse($this->serializer->normalize($periodArticle, 'json', ['groups' => 'medium']));
    }

编辑:@aynber,@hakre 查询是

INSERT INTO region_attribute (description, combination, additional_description, internal_note, agency_note, sales_agency_note, do_not_show, active_pictures, promotion_price, special_price, special_description, payback, new_in_assortment, give_away, recommendation, deleted_at, region_id, master_article_id, master_mix_group_id, master_container_id, period_article_id, period_mix_group_id, period_container_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
参数和类型是空数组

编辑:关于球童更新的时间,我们也更新了

composer.lock
。教义方面发生了许多变化。使用前一天的composer.lock构建应用程序并不是一个干净的解决方案,但这将是我们的修复方案,直到我们找出到底需要更改哪些内容才能与新版本一起使用。

php symfony doctrine mariadb-10.3
2个回答
0
投票

谢谢您的帮助。

问题不在于球童,正如已经审查过的那样,而是在于我们的composer.lock中有关教义的版本升级,这是我们只能自己解决的问题,所以我结束了这个问题。


0
投票

您缺少将值替换为问号占位符的代码。让我们看看带有“execute”和“bind”的 PHP 代码(或者 Symphony/doctrine 所需的任何语法)。

© www.soinside.com 2019 - 2024. All rights reserved.