sql-server - 如何在我的 symfony 项目中将 SQL Server 与 ORM Doctrine 连接起来?
问题描述
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
host: 127.0.0.1
port: 8889
user: '%env(DATABASE_USER)%'
password: '%env(DATABASE_PWD)%'
dbname: '%env(DATABASE_NAME)%'
# With Symfony 3.3, remove the `resolve:` prefix
# url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: yml
dir: '%kernel.project_dir%/config/doctrine'
prefix: 'App\Entity'
alias: App
解决方案
您需要使用驱动程序pdo_sqlsrv
或sqlsrv
,而不是pdo_mysql
。
(参见学说配置文档)。
pdo_sqlsrv:使用 pdo_sqlsrv PDO 的 Microsoft SQL Server 驱动程序
sqlsrv:使用 sqlsrv PHP 扩展的 Microsoft SQL Server 驱动程序。
pdo_sqlsrv
/的可用配置sqlsrv
是:
user (string): Username to use when connecting to the database.
password (string): Password to use when connecting to the database.
host (string): Hostname of the database to connect to.
port (integer): Port of the database to connect to.
dbname (string): Name of the database/schema to connect to.
文档说:
以下驱动程序支持开箱即用的自动数据库平台检测,无需任何额外配置:
pdo_mysql mysqli pdo_pgsql pdo_sqlsrv sqlsrv
所以你不需要指定server_version
.
你将会拥有:
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_sqlsrv'
charset: utf8mb4
host: 127.0.0.1
port: 8889
user: '%env(DATABASE_USER)%'
password: '%env(DATABASE_PWD)%'
dbname: '%env(DATABASE_NAME)%'
# With Symfony 3.3, remove the `resolve:` prefix
# url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: yml
dir: '%kernel.project_dir%/config/doctrine'
prefix: 'App\Entity'
alias: App
推荐阅读
- ruby-on-rails - Ruby 类级别变量和 Rails class_attribute 有什么区别?
- ffmpeg - 使用 ffmpeg 将 mp3 转换为 mp4 - 如何在生成的视频上绘制文件名?
- python-3.x - python3,boto3,aws ec2实例的第二个ip获取
- r - R - 按条件创建数据框
- angular - 文件不存在,但角度说它已经存在
- python - Python 和 Flask:IndentationError: unindent 不匹配任何外部缩进级别
- r - 使用 dplyr 计算子集内子集的比率
- c# - Gremlin cosmos:如何在重复命令中将边缘的属性值复制为顶点属性
- java - 在移动设备中显示背景良好,但在 bluestacks 中显示白色背景
- sql - 通过连接或其他方式根据匹配的 ID 在表列中填充空行