cdb connection连接数据库失败 什么原因
3个回答
展开全部
先将yii框架的debug模式打开,
[root@xyhz /xyhz/bugfree3.0.3 ]#vim index.php
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/lib/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
if(!file_exists($config))
{
header( 'Location: install' ) ;
}
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config)->run();
然后你会看到一些报错:如下:
CDbConnection 无法开启数据库连线: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
/xyhz/bugfree3.0.3/lib/db/CDbConnection.php(364)352 throw new CDbException(Yii::t('yii','CDbConnection.connectionString cannot be empty.'));
353 try
354 {
355 Yii::trace('Opening DB connection','system.db.CDbConnection');
356 $this->_pdo=$this->createPdoInstance();
357 $this->initConnection($this->_pdo);
358 $this->_active=true;
359 }
360 catch(PDOException $e)
361 {
362 if(YII_DEBUG)
363 {
364 throw new CDbException(Yii::t('yii','CDbConnection failed to open the DB connection: {error}',
365 array('{error}'=>$e->getMessage())),(int)$e->getCode(),$e->errorInfo);
366 }
367 else
368 {
369 Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
370 throw new CDbException(Yii::t('yii','CDbConnection failed to open the DB connection.'),(int)$e->getCode(),$e->errorInfo);
371 }
372 }
373 }
374 }
375376 /**
重点是在: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)这句话了,这说明你的mysql不是默认安装的,这时你在做个软链接过去就行了
[root@xyhz /xyhz/bugfree3.0.3 ]#vim index.php
<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/lib/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
if(!file_exists($config))
{
header( 'Location: install' ) ;
}
// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
require_once($yii);
Yii::createWebApplication($config)->run();
然后你会看到一些报错:如下:
CDbConnection 无法开启数据库连线: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
/xyhz/bugfree3.0.3/lib/db/CDbConnection.php(364)352 throw new CDbException(Yii::t('yii','CDbConnection.connectionString cannot be empty.'));
353 try
354 {
355 Yii::trace('Opening DB connection','system.db.CDbConnection');
356 $this->_pdo=$this->createPdoInstance();
357 $this->initConnection($this->_pdo);
358 $this->_active=true;
359 }
360 catch(PDOException $e)
361 {
362 if(YII_DEBUG)
363 {
364 throw new CDbException(Yii::t('yii','CDbConnection failed to open the DB connection: {error}',
365 array('{error}'=>$e->getMessage())),(int)$e->getCode(),$e->errorInfo);
366 }
367 else
368 {
369 Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
370 throw new CDbException(Yii::t('yii','CDbConnection failed to open the DB connection.'),(int)$e->getCode(),$e->errorInfo);
371 }
372 }
373 }
374 }
375376 /**
重点是在: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)这句话了,这说明你的mysql不是默认安装的,这时你在做个软链接过去就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
贴出链接数据库的代码看看 你是怎么链接的
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
能贴出你连接数据库的代码么?连接数据库失败的原因可能很多种,得看你代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询