Zend 框架和 SQL Server [英] Zend Framework and SQL Server

查看:22
本文介绍了Zend 框架和 SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Zend Framework 与 SQL server 2005 express(通过 Pdo_Mssql 和 wamp安装)但似乎 pdo 无法连接到 SQL.这是我的代码:

I'm trying to use Zend Framework with SQL server 2005 express (through Pdo_Mssql with wamp installation) but seem that pdo can't connect to SQL. This is my code:

require '../application/bootstrap.php'; 

try {
    $db = Zend_Db::factory('Pdo_Mssql', array(
    'host'     => 'localhost',
    'username' => 'sa',
    'password' => 'verystrongpass',
    'dbname'   => 'msdb'
));
    $db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
    $e->getMessage();
} catch (Zend_Exception $e) {
   $e->getMessage();
}


$sql = 'SELECT * FROM table';

$result = $db->fetchAll($sql);

echo "----------------" . var_dump($result);

并且错误结果总是:

致命错误:未捕获的异常'Zend_Db_Adapter_Exception' 与消息 'SQLSTATE[01002] 无法连接:SQL Server 不可用或不存在.(严重性 9)' 在C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Abstract.php:130堆栈跟踪:#0C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Mssql.php(135):Zend_Db_Adapter_Pdo_Abstract->_connect()

Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'SQLSTATE[01002] Unable to connect: SQL Server is unavailable or does not exist. (severity 9)' in C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Abstract.php:130 Stack trace: #0 C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Mssql.php(135): Zend_Db_Adapter_Pdo_Abstract->_connect()

1C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Abstract.php(389):Zend_Db_Adapter_Pdo_Mssql->_connect()

1 C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Abstract.php(389):Zend_Db_Adapter_Pdo_Mssql->_connect()

2C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Abstract.php(205):Zend_Db_Adapter_Abstract->query('SELECT* FROM t...', Array)

2 C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Abstract.php(205):Zend_Db_Adapter_Abstract->query('SELECT * FROM t...', Array)

3C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Abstract.php(616):Zend_Db_Adapter_Pdo_Abstract->query('SELECT* FROM t...', Array)

3 C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Abstract.php(616): Zend_Db_Adapter_Pdo_Abstract->query('SELECT * FROM t...', Array)

4 C:\Documents 和Settings\Luca\Documenti\Workspace\web\db\public\index.php(27):Zend_Db_Adapter_Abstract->fetchAll('SELECT * FROM t...') #5 {main} 被抛出到 C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Abstract.php在线 130

4 C:\Documents and Settings\Luca\Documenti\Workspace\web\db\public\index.php(27): Zend_Db_Adapter_Abstract->fetchAll('SELECT * FROM t...') #5 {main} thrown in C:\wamp\bin\php\php5.2.5\lib\Zend\Db\Adapter\Pdo\Abstract.php on line 130

那么有没有人对ZF + SQL server 有一些经验,SQL server 需要一些特殊的配置吗?在安装时,我只指定使用默认值并使用混合身份验证.而且我可以通过Microsoft SQL server management studio express 成功连接db.

So anyone have some experience with ZF + SQL server, SQL server need some special configuration? In istallation time i've only specify to use the default istance and to use mixed authentication. Moreover I can successful connect with db through Microsoft SQL server management studio express.

推荐答案

所有 SQL Server Express 安装在 SQLEXPRESS 的命名实例而不是默认实例上 - 请参阅 这个.

All SQL Server Express installations on a named instance of SQLEXPRESS rather than a default instance - see this.

所以你的主机应该看起来像

So your host should look like

'host'     => 'localhost\SQLEXPRESS'

这篇关于Zend 框架和 SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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