求助:cakephp连接不上数据库

chengyk 发布于 2013/12/03 15:58
阅读 1K+
收藏 0

我想使用数据库test,测试一下联通性。app/config/database.php文件代码修改后如下:

DATABASE_CONFIG {


public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'root',
'password' => 'root',
'database' => 'test',
'prefix' => '',
//'encoding' => 'utf8',
)

测试结果:

Your database configuration file is present.

CakePHP is NOT able to connect to the database.

Database connection "Mysql" is missing, or could not be created.
Selected driver is not enabled

不知道怎么解决。求助各位高手。

加载中
0
Tuesday
Tuesday

目测是mysql驱动没开.修改一下:

'datasource' => 'Database/Mysqli',

0
c
chengyk

不行。

测试结果:

Your database configuration file is present.

CakePHP is NOT able to connect to the database.

Datasource class Mysqli could not be found. 
Datasource is not found in Model/Datasource package.

噢。我忘了说了。我是windows环境下的,不知道有没有影响

0
c
chengyk

哦哦。是我忘了给你复制这句了:Your version of PHP is 5.2.8 or higher.

非常对不起。这句才是关键啊我把php换成5.3的。就解决了。

0
找个没人用的名字
找个没人用的名字
include("app/Config/database.php");
$config= new DATABASE_CONFIG();

$name = 'default';

$settings=$config->{$name};
$dsn = 'mysql:dbname='.$settings['database'].';host='.$settings['host'];
$user = $settings['login'];
$password = $settings['password'];

try {
    $dbh = new PDO($dsn, $user, $password);
    echo "Connection succeeded with dsn: ". $dsn . "\n";
    $sql = 'SELECT id, title FROM posts';
    echo "Here is the contents of the table `posts:";
    foreach ($dbh->query($sql) as $row) {
        print $row['id'] . "\t" . $row['title'] . "\n";
    }
} catch (PDOException $e) {
    echo 'PDO error: ' . $e->getMessage();
}


检查一下PDO驱动,创建这个测试文件看看;

正常返回:=> return:Connection succeeded with dsn: mysql:dbname=test;host=127.0.0.1 Here is the contents of the tableposts:`

异常返回:PDO error: could not find driver;(进入php.ini => 去掉extension=php_pdo_mysql.dll前面的分号)

我是window环境,问题解决!

原文地址:

http://stackoverflow.com/questions/20760567/cakephp-2-0-database-connection-mysql-is-missing-or-could-not-be-created

建议大家Google,度娘真心找不到答案!!

返回顶部
顶部