我是 Symfony2 的新手。我正在开发一个实用程序服务,它需要使用数据库来满足自己的需求。
我希望它的数据与其他服务/包使用的 mysql 全局数据库分开。
存储db文件的最佳位置在哪里以及如何指定路径?
示例(错误)代码:
class MyCustomService
{
protected $config;
public function __construct(array $config)
{
$this->config = $config;
$this->setupDB();
}
private function setupDB()
{
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'driver' => 'pdo_sqlite',
'path' => realpath('.') . '\dbmanager.db'
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
//...
}
}
感谢您的帮助
最佳答案
It Shouldn't be in web folder :)
如果您的数据库可以在清除缓存时删除,那么应用程序/缓存就可以了。
如果您想要持久数据库,那么您可以选择 app/{name of service}/db.sqlite"或 data/{name of service}/db.sqlite"中的某个位置
我宁愿在配置选项中传递数据库的名称
Also note that under *NIX the user of your web server/cli must have read and write permissions on the database file and read, write and execute permissions on the containing directory
关于sqlite - 存储我的服务 sqlite 数据库文件的最佳位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14937243/