【发布时间】:2019-01-04 07:36:25
【问题描述】:
我有这个代码:
try{
$aws = $this->getContainer()->get(Service::class);
$query = 'DROP TABLE IF EXISTS newtable;CREATE TABLE newtable LIKE actions;';
$aws->executeQuery($query);
}catch (\Exception $exception){
$output->writeln("Can't create new tables, with message :");
$output->writeln(sprintf("%s", $exception->getMessage()));
}
还有Service类函数executeQuery:
public function executeQuery($query, $multiple = true, $fetch = true)
{
$res = $this->conn->prepare($query);
$result = $res->execute();
return ($fetch) ? ($multiple ? $res->fetchAll(\PDO::FETCH_ASSOC) : $res->fetch(\PDO::FETCH_ASSOC)) : $result;
}
表已创建,但我收到错误消息:
SQLSTATE[HY000]: General error。我不明白删除此错误的问题是什么。感谢您的帮助。
【问题讨论】:
-
Symfony 使用原则,不是吗?看这个问题,可能与你想要的有关:stackoverflow.com/questions/14041484/mysql-with-symfony2
-
@Mickael Leger 建议使用 Doctrine 不是必须的
-
General error,你能提供更多信息吗?看来您与数据库的连接有问题,您确定连接一切正常吗?尝试一些简单的查询? -
正如我所说的表已创建,所以连接良好
标签: php symfony symfony-2.1