简体   繁体   English

如何在Microsoft SQL Server数据库中使用PHPUnit的DBUnit?

[英]How can I use PHPUnit's DBUnit with a Microsoft SQL Server database?

I'm using PHPUnit and DBUnit to create tests for a PHP application that runs on the commandline and inserts data into a Microsoft SQL Server database. 我正在使用PHPUnit和DBUnit为在命令行上运行并将数据插入Microsoft SQL Server数据库的PHP应用程序创建测试。

The DBUnit documentation ( https://phpunit.de/manual/current/en/database.html#database.supported-vendors-for-database-testing ) states that Microsoft SQL Server is not supported but is accessible through the Zend Framework or Doctrine 2. DBUnit文档( https://phpunit.de/manual/current/en/database.html#database.supported-vendors-for-database-testing )指出,不支持Microsoft SQL Server,但可以通过Zend Framework或教义2。

When I attempt: 当我尝试:

 $pdo = new PDO( "odbc:Driver={ODBC Driver 13 for SQL Server};Server=redacted", $user, $passwd );

 $this->createDefaultDBConnection($pdo, $db);

I get, not surprisingly, the following error: 毫不奇怪,我得到以下错误:

PHPUnit_Extensions_Database_Exception: Could not find a meta data driver for odbc pdo driver.

I found Zend Framework documentation that shows how to use PHPUnit to write tests related to relational databases ( https://framework.zend.com/manual/1.10/en/zend.test.phpunit.db.html ), and I think I could get that to work if I understood Zend better, so it's possible what I need is some help understanding how to get access to the Zend classes w/out writing an entire Zend application. 我找到了Zend Framework文档,该文档显示了如何使用PHPUnit编写与关系数据库相关的测试( https://framework.zend.com/manual/1.10/en/zend.test.phpunit.db.html ),我认为如果我对Zend的了解更好,它可以使它正常工作,因此我可能需要一些帮助来了解如何在不编写整个Zend应用程序的情况下访问Zend类。

But maybe there's some non-Zend way to do it. 但是也许有一些非Zend的方法可以做到这一点。

If your problem is the PDO connection, I would recommend trying to use the pdo_sqlsrv driver that's bundled with the SQL Server Driver for PHP . 如果您的问题是PDO连接,我建议您尝试使用与SQL Server Driver for PHP捆绑在一起的pdo_sqlsrv驱动程序 The connection string you have to use would look something like this: 您必须使用的连接字符串如下所示:

new PDO("sqlsrv:Server=localhost;Database=testdb", "UserName", "Password");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM