我正在使用Zend Framework 2并尝试创建用于填充db config的控制台命令
php public/index.php env install stable --dbu=root --dbp=root --dbn=panel100
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'username'@'localhost' (using password: YES)' in /home/seyfer/www/site.loc/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43
Stack trace:
#0 /home/seyfer/www/site.loc/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(43): PDO->__construct('mysql:host=loca...', 'username', 'password', Array)
#1 /home/seyfer/www/site.loc/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php(45): Doctrine\DBAL\Driver\PDOConnection->__construct('mysql:host=loca...', 'username', 'password', Array)
#2 /home/seyfer/www/site.loc/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(360): Doctrine\DBAL\Driver\PDOMySql\Driver->connect(Array, 'username', 'password', Array)
#3 /home/seyfer/www/site.loc/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): Doctrine\DBAL\Connection->connect()
#4 /home/seyfer/www/site.loc/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(3 in /home/seyfer/www/site.loc/vendor/zendframework/zend-servicemanager/src/ServiceManager.php on line 946
所以我没有鸡和蛋的问题。命令失败,因为没有DB配置,但命令应该创建此配置。
调用此命令时如何不初始化服务?
我的控制器代码是
use Zend\Mvc\Controller\AbstractActionController;
use ZendMover\Copier;
class EnvController extends AbstractActionController
{
public function installAction()
{
$env = $this->getRequest()->getParam('env');
$dbu = $this->getRequest()->getParam('dbu');
$dbp = $this->getRequest()->getParam('dbp');
$dbn = $this->getRequest()->getParam('dbn');
try {
$environment = new Environment($env, new Copier());
$result = $environment->installEnv($env, $dbu, $dbp, $dbn);
return $result ? "Success\n" : '';
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
}
}
}
答案 0 :(得分:0)
我用Symfony控制台组件解决了这个问题。
但是如何使用Zend Console解决它?