2013-04-24 95 views
0

我有一个新的域&托管,但我无法连接到新的数据库。数据库连接Yii框架

我试了一下:

'db'=>array(
    'connectionString' => 'mysql:host=ascodcurro.com.mysql;dbname=ascodcurro_com', 
    'emulatePrepare' => true, 
    'username' => 'ascodcurro_com', 
    'password' => 'xxxx', 
    'charset' => 'utf8', 
    ),  

如果我尝试localhost作为始终正常工作。从主机 用户信息:

MySQL 
server: ascodcurro.com.mysql 
DB: ascodcurro_com 
user: ascodcurro_com 
pw: ***** 

PhpMyAdmin 
PhpMyAdmin: https://dbadmin.one.com/ 
user: ascodcurro_com 
pw: ****** 

回答

4

在初次启动和Yii工作期间,我遇到的第一个问题是连接到数据库。

我得到了一个非常奇怪的错误,我无法在我的XAMPP堆栈上的Mac OSX Mountain Lion上连接到我的数据库。经过无数次的搜索,我终于找到了一种可行的方法。这是我能够连接到我的Yii数据库的唯一途径。

  1. 首先检查是否可以连接到数据库正常使用 默认配置由 main.php文件取消对“DB”的配置。例如:

    'db'=>array(
    
          'connectionString' => 'mysql:host=localhost;dbname=ascodcurro_com', 
          'emulatePrepare' => true, 
          'username' => 'username', 
          'password' => 'pass', 
          'charset' => 'utf8', 
          'tablePrefix'=>'', 
          'enableProfiling'=>true, 
          'enableParamLogging'=>true, 
    
    
         ), 
    

但是,如果你仍然无法即使这对连接到数据库,因为我不能够连接到矿山,尝试采用这种方法: 创建一个新的PHP文件类型:

<?php phpinfo() ?> 

检查该网页时,找出“MySQL的”位于并找出其中的“MYSQL_SOCKET”并记下位置。

注意到位置下来之后,试试这个作为你的“DB”连接字符串(例如,用于我的位置是“/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock”):

'connectionString' => 'mysql:unix_socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock;dbname=practice', 

其余的作为您使用的基本参数。 然后再次尝试连接。

希望能够将您连接到您的数据库。

Regards,

+0

伟大的Word老兄! – 2015-04-11 08:26:19

1
'db'=>array(

      'connectionString' => 'mysql:host=localhost;dbname=basename', 
      'emulatePrepare' => true, 
      'username' => 'username', 
      'password' => 'pass', 
      'charset' => 'utf8', 
      'tablePrefix'=>'', 
      'enableProfiling'=>true, 
      'enableParamLogging'=>true, 


     ), 

其我的配置。你有任何错误?