我正在尝试为我的PHP Web应用程序使用Doctrine 2 ORM,但我遇到了一个我无法弄清楚的问题。
为了测试,我使用的是Vagrant,安装了Scotchbox(安装了一个基本的LAMP堆栈(。
我正在尝试运行$vendor/bin/doctrine orm:schema-tool:create,但不断收到此错误:
[Doctrine''DBAL''Exception''ConnectionException]
驱动程序中发生异常:没有此类文件或目录
[Doctrine''DBAL''Driver''Mysqli''MysqliException]
没有这样的文件或目录
这是我的连接参数:
$isDevMode = true;
$paths = array("db-entities/");
$dbParams = array(
'driver' => 'mysqli',
'user' => 'root',
'password' => 'root',
'dbname' => 'scotchbox'
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);
如果我在数组中添加一个"host"=> '127.0.0.1',则会出现不同的错误:
[Doctrine''DBAL''Exception''ConnectionException]
驱动程序中发生异常:连接被拒绝
[Doctrine''DBAL''Driver''Mysqli''MysqliException]
连接被拒绝
如果我尝试使用标准 mysqli 调用连接,它可以工作(DB_HOST = '本地主机'(:
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$mysqli) {
die("Database connection failed:");
}
我不确定我哪里出错了??
检查您是否在流浪机器上安装了php-mysql
。
对于那些可能也遇到此问题的人,这是解决方案:
只需更新 Vagrantfile 以使用 rsync:
config.vm.synced_folder ".", "/var/www", type: "rsync",
rsync__exclude: ".git/"
而不是默认值:
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
每次要更新虚拟机时都需要运行vagrant rsync
,但现在可以通过 ssh 加入并成功运行以下命令:
$vendor/bin/doctrine orm:schema-tool:create