我需要将Symfony2与我们的MSSQL Server连接。
我们已经在Ubuntu中使用PHP 5.3和pdo_dblib安装了Apache,所以我按照说明安装了包LSWDoctrinePdoDblib
我的app / config / config.yml看起来像:
# Doctrine Configuration
doctrine:
dbal:
#driver: %database_driver%
driver_class: Lsw\DoctrinePdoDblib\Doctrine\DBAL\Driver\PDODblib\Driver
host: %database_host%
#host: mssql_freetds
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: %kernel.root_dir%/data/data.db3
# path: %database_path%
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
我的app / config / parameters.yml(含假数据):
parameters:
database_driver: pdo_dblib
database_host: 10.0.0.33
database_port: '1433'
database_name: DB_CONECTAR
database_user: user_dba
我一直按照here的说明操作,当我运行命令时:
php app/console doctrine:mapping:convert xml ./src/DBP/GestionWSBundle/Resources/config/doctrine --from-database --force
然后我得到了下一个错误,但SQL显示其工作正常。
[Doctrine\DBAL\DBALException]
An exception occurred while executing 'SELECT col.name,
type.name AS type,
col.max_length AS length,
~col.is_nullable AS notnull,
def.definition AS [default],
col.scale,
col.precision,
col.is_identity AS autoincrement,
col.collation_name AS collation
FROM sys.columns AS col
JOIN sys.types AS type
ON col.user_type_id = type.user_type_id
JOIN sys.objects AS obj
ON col.object_id = obj.object_id
LEFT JOIN sys.default_constraints def
ON col.default_object_id = def.object_id
AND col.object_id = def.parent_object_id
WHERE obj.type = 'U'
AND obj.name = 'MAILING_LISTS'':
SQLSTATE[HY000]: General error: 4004 General SQL Server error: Check messages from the SQL Server [4004] (severity 16) [SELECT col.name,
type.name AS type,
col.max_length AS length,
~col.is_nullable AS notnull,
def.definition AS [default],
col.scale,
col.precision,
col.is_identity AS autoincrement,
col.collation_name AS collation
FROM sys.columns AS col
JOIN sys.types AS type
ON col.user_type_id = type.user_type_id
JOIN sys.objects AS obj
ON col.object_id = obj.object_id
LEFT JOIN sys.default_constraints def
ON col.default_object_id = def.object_id
AND col.object_id = def.parent_object_id
WHERE obj.type = 'U'
AND obj.name = 'MAILING_LISTS']
知道我该怎么办?非常感谢你提前!!
正如我所提到的,我正在使用https://github.com/LeaseWeb/LswDoctrinePdoDblib正如您可以在网站末尾阅读的那样,他尝试做同样的事情并做到了:
你知道我该怎么办?我甚至都不知道如何查找这些信息。
答案 0 :(得分:1)
查看pdo-dblib in php.net文档的评论我发现DB-Library不支持unicode,所以如果SQL有一个类型为ntext | nvarchar | etc的字段,那么给出错误4004.
所以我去的地方是"坏" SQL并将所有字段(vendor / doctrine / dbal / lib / Doctrine / DBAL / Platforms / SQLServerPlatform.php)转换为另一种类型:
public function getListTableColumnsSQL($table, $database = null)
{
return "SELECT CAST(col.name AS text) as name,
CAST(type.name AS text) AS type,
CAST(col.max_length AS real) AS length,
cast(~col.is_nullable as bit) AS notnull,
cast(def.definition as bit) AS [default],
cast(col.scale as real) as scale,
cast(col.precision as real) as precision,
cast(col.is_identity as bit) AS autoincrement,
cast(col.collation_name as text) AS collation
FROM sys.columns AS col
JOIN sys.types AS type
ON col.user_type_id = type.user_type_id
JOIN sys.objects AS obj
ON col.object_id = obj.object_id
LEFT JOIN sys.default_constraints def
ON col.default_object_id = def.object_id
AND col.object_id = def.parent_object_id
WHERE obj.type = 'U'
AND obj.name = '$table'";
}
这是一个临时解决方案,我想将它合并到捆绑或其他东西,但现在我真的不知道如何制作捆绑或我应该如何以正确的方式修改它我知道我会在这里分享这些信息。
这样做我得到了包含所有表元数据的xml。
答案 1 :(得分:1)
在freetds配置文件(/etc/freetds/freetds.conf)中替换
[global]
tds version = 4.2
使用:
[global]
tds version = 8.0
答案 2 :(得分:1)
请检查一下。
/etc/freetds.conf中的:
;tds version = 4.2
tds version = 8.0
client charset = UTF-8
在php.ini中:
mssql.charset = "UTF-8"
default_charset = "utf-8"
这个问题是因为字符编码。
由于