symfony2项目中如何使用sqlite数据库? [英] How to use sqlite database on symfony2 project?

查看:183
本文介绍了symfony2项目中如何使用sqlite数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Symfony2项目中,您可以在app / config / parameters.ini文件中配置数据库连接。文档声明您可以使用sqlite3 PDO驱动程序。

In a Symfony2 project, you can configure the databases connections at the app/config/parameters.ini file. Documentation states that you can use, among others, sqlite3 PDO driver.

但是配置sqlite不正确:

But configuring sqlite doesn't works well:

[parameters]
    database_driver   = pdo_sqlite
    database_host     = localhost
    database_port     =
    database_name     = test_project.db
    database_user     = root
    database_password = 

使用app / console doctrine:database:create,成功创建一个test_project .db文件在项目根目录下。

Using app/console doctrine:database:create, successfully creates a test_project.db file at the project root directory.

但创建一些实体后,运行app / console原则:schema:update --force应该在数据库上创建表文件,但没有,文件显示为空,O字节大小。

But after creating some entities, then running app/console doctrine:schema:update --force should create the tables on the database file, but it doesn't, file appears empty, with O bytes size.

请注意,使用其他PDO驱动程序工作正常,但不能与SQLite ...

Note that using any other PDO driver works well, but not with SQLite...

我还尝试在database_name参数中使用db文件的完整路径,但无济于事,数据库仍然无法获取更新。

I've also tried to use the full path for the db file in the database_name parameter, but to no avail, database still doesn't gets updated.

为了参考,这里是config.yml文件的doctrine dbal部分:

For reference, here's the doctrine dbal section of the config.yml file:

doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8


$ b $有没有办法呢?配置丢失?

Is there a way around this? configurations missing? something not stated on the official doc of symfony2 project?

推荐答案

根据 Doctrine 用于sqlite DBAL配置的元素是:

According to Doctrine the elements used for sqlite DBAL configuration are:


  • 用户 (string):连接数据库时使用的用户名。

  • 密码 (字符串):连接数据库时要使用的密码。

  • 路径 (string):数据库文件的文件系统路径。与记忆互斥路径优先。

  • 内存 (boolean):如果SQLite数据库应该在内存中(非持久性),则为true。与路径相互排斥路径优先。

  • user (string): Username to use when connecting to the database.
  • password (string): Password to use when connecting to the database.
  • path (string): The filesystem path to the database file. Mutually exclusive with memory. path takes precedence.
  • memory (boolean): True if the SQLite database should be in-memory (non-persistent). Mutually exclusive with path. path takes precedence.

这也列在完整的 Doctrine配置参考

所以你需要切换您的配置参数以匹配适合sqlite的内容。

So you need to switch up your config params to match whats appropriate for sqlite.

这篇关于symfony2项目中如何使用sqlite数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆