通过Zend框架连接到MsSql Db SQLSTATE [](null)(严重性0)

时间:2014-01-27 11:33:13

标签: php sql-server apache zend-framework pdo

我在从mac连接到db(mssql)时遇到问题。我已经安装了freetds和dblib与自制广告他们应该工作,但我phpinfo()说:

 '--enable-pdo' '--with-pdo-sqlite' '--with-pdo-mysql=mysqlnd' '--with-readline=/usr/local/readline-6.2' '--with-libedit' '--with-pdo-pgsql' '--with-iconv' '--with-sqlite3' '--disable-phar' '--enable-xmlwriter' '--enable-xmlreader' '--enable-mysqlnd' 

在此之后,在一个单独的部分:

Additional .ini files parsed: /usr/local/zend/etc/conf.d/pdo_dblib.ini, /usr/local/zend/etc/conf.d/mssql.ini,

然后:

 pdo_dblib
 PDO Driver for FreeTDS/Sybase DB-lib   enabled
 Flavour    freetds 

 mssql
 MSSQL Support  enabled
 Active Persistent Links    0
 Active Links   0
 Library version    FreeTDS 

我无法理解库是否有效启用,因为连接以下配置会出现以下错误:

 resources.db.adapter = pdo_mssql
 resources.db.isDefaultAdapter = true
 resources.db.params.host = "host"
 resources.db.params.port = "port"
 resources.db.params.username = "un"
 resources.db.params.password = "pw"
 resources.db.params.dbname = "name"
 resources.db.params.pdoType = dblib
 resources.db.params.charset= "utf-8"

错误:

 SQLSTATE[] (null) (severity 0) 

来自freenode上的## zftalk频道:

 thats usually what you get when you use pdo->lastError() when no error has actually happened

这是我在PHPinfo()

中的mssql支持
 MSSQL Support  enabled
 Active Persistent Links    0
 Active Links   0
 Library version    FreeTDS

 Directive  Local Value Master Value
 mssql.allow_persistent On  On
 mssql.batchsize    0   0
 mssql.charset  no value    no value
 mssql.compatability_mode   On  On
 mssql.connect_timeout  5   5
 mssql.datetimeconvert  On  On
 mssql.max_links    Unlimited   Unlimited
 mssql.max_persistent   Unlimited   Unlimited
 mssql.max_procs    Unlimited   Unlimited
 mssql.min_error_severity   10  10
 mssql.min_message_severity 10  10
 mssql.secure_connection    On  On
 mssql.textlimit    Server default  Server default
 mssql.textsize Server default  Server default
 mssql.timeout  60  60  

1 个答案:

答案 0 :(得分:2)

检查您的freetds配置和resources.db.params.host = "host"设置

前一段时间我使用此配置连接RHEL上的php 5 / ZF 1.x - 但也许会有所帮助。 host是SQL Server的地址,[my-server-name]只是配置文件中的部分名称。

/usr/local/etc/freetds.conf
[my-server-name]
host = 10.0.0.1
port = 1433
tds version = 8.0

然后在我使用的app.ini中(在freetds.conf中使用host ==配置条目)

db.config.host      = my-server-name
db.config.username  = user
db.config.password  = pass
db.config.dbname    = DBNAME

(我的app.ini db.config条目应与您的resources.db.params

相对应