加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

存储我的服务sqlite db文件的最佳位置?

发布时间:2020-12-12 18:54:21 所属栏目:百科 来源:网络整理
导读:我是Symfony2的新手.我正在开发一种需要根据自己的需要使用数据库的实用程序服务. 我希望它的数据与其他服务/包使用的mysql全局数据库保持分离. 存储db文件的最佳位置在哪里以及如何指定路径? 样本(坏)代码: class MyCustomService{ protected $config; pu
我是Symfony2的新手.我正在开发一种需要根据自己的需要使用数据库的实用程序服务.

我希望它的数据与其他服务/包使用的mysql全局数据库保持分离.

存储db文件的最佳位置在哪里以及如何指定路径?

样本(坏)代码:

class MyCustomService
{
    protected $config;

    public function __construct(array $config)
    {
        $this->config = $config;
        $this->setupDB();
    }    

    private function setupDB()
    {
        $config = new DoctrineDBALConfiguration();
        $connectionParams = array(
            'driver' => 'pdo_sqlite','path' => realpath('.') . 'dbmanager.db'
        );        
       $conn = DoctrineDBALDriverManager::getConnection($connectionParams,$config); 

       //...
    }
}

谢谢你的帮助

解决方法

It Shouldn't be in web folder :)

>如果您的数据库可以在清除缓存时删除,那么app / cache就可以了.
>如果你想要持久数据库,那么你可以选择app / {name of service} /db.sqlite“或data / {name of service} /db.sqlite”中的某个地方
>我宁愿在配置选项中传递DB的名称

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读