What's this error from a simple db unit test of Yii?
root@u10开发者_运维知识库10:/opt/lampp/htdocs/trackstar/protected/tests# phpunit unit/DbTest.php
PHPUnit 3.4.13 by Sebastian Bergmann.
E
Time: 2 seconds, Memory: 5.75Mb
There was 1 error:
1) DbTest::testConnection
CDbException: CDbConnection failed to open the DB connection.
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:275
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:242
/opt/lampp/htdocs/yii/framework/db/CDbConnection.php:221
/opt/lampp/htdocs/yii/framework/base/CModule.php:363
/opt/lampp/htdocs/yii/framework/base/CModule.php:86
/opt/lampp/htdocs/trackstar/protected/tests/unit/DbTest.php:6
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
root@u1010:/opt/lampp/htdocs/trackstar/protected/tests#
You should edit the 'db' component declaration in protected/config/test.php
This configuration file is used when you're running your tests.
Check protected/tests/bootstrap.php to see the included files.
Okay. After about half a day of pulling my hair out. This is all I had to do. Hope it helps others. Several simple checks solved this issue. I've got multiple copies of both php and phpunit with different paths. I'm assuming you have your /requirements/index.php checks passed, and your config/main & test files set.
In terminal locate your PHPUnit executable:
which phpunit
Locate your running php executable:
which php
sudo vi path/to/phpunit (the executable)
make sure that the first line referencing the php exectuable is actually the one from step two.
Solved my headache. :)
It could not connect to your database. Either:
- Your database connection settings are incorrect.
- Your database is not running.
- There is a networking misconfiguration.
try:
mysql_connect("127.0.0.1", "root", "123456") or die (mysql_error());
echo "Connected to MySQL";
sometimes the privileges setting for the MySQL server are different for "127.0.0.1" and "localhost". If this is the case, you can do:
mysql> GRANT ALL PRIVILEGES ON trackstar_dev.* TO 'root'@'127.0.0.1';
on your mysql server
精彩评论