sqlite - 存储我的服务 sqlite 数据库文件的最佳位置?

标签 sqlite symfony doctrine-orm

我是 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/

相关文章:

java - Android无法将日期时间写入sqlite数据库

sql - 2. 不相关表连接的优化

php-7 - PHP7 与 Symfony3 兼容吗?

php - Sylius:添加具有可翻译内容的资源

php - Symfony2 : Prevent duplicate in database with form Many to One

sqlite - 加快某些 SQLite 数据的加载时间

c++ - Qt-C++通过绝对路径连接Sqlite

symfony - 如何在 nginx 的子目录中安装 symfony2 应用程序

php - Symfony2 PHPUnit 时钟模拟不起作用

symfony - 无法使用 MAMP 在 Symfony2 中为 Doctrine2 创建数据库连接(连接被拒绝)