0

I am developing an application localy, and want to connect to live database, but when trying to get to gii's crud generator I am given the following error:

CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

if(Yii::app()->db===null)

There is no problem to connect to a local database, so I guess it has something to do with XAMPP or firewall settings but I cannot figure out what.

Many thanks in advance.

Johhny P
  • 163
  • 1
  • 2
  • 9
  • 1
    Try check connection from another application: If U use mysql - try `mysql -u{username} -h{address of live db} -P` – Sergey Feb 19 '13 at 12:10
  • Connection to the same database is working well from a different application – Johhny P Feb 19 '13 at 12:29
  • 1
    Do you connect via file socket or IP? – schmunk Feb 19 '13 at 12:43
  • @JohhnyP, when check user/host/pass in config.php. Also check version of mysql client on local and mysql live db – Sergey Feb 19 '13 at 13:43
  • @schmunk, I am pretty much a newbie here, but I connect by entering host domain name, username and password, without setting anything else, just basic Yii settings – Johhny P Feb 19 '13 at 17:27
  • @Sergey, I have double checked and copy pasted the data. I am connected to the same DB from live cakePHP app and it works perfectly. Mysql version on local db is 5.5.25a on live db 5.1.56. So that might cause the problem, but I cannot upgrade it. – Johhny P Feb 19 '13 at 17:28
  • 2
    Post you db config on main.php – FabianoLothor Feb 19 '13 at 17:30
  • What @FabianoLothor also check index.php in root directory to make sure it is pointing at main.php not another config file. If it is make sure it isn't overwriting your db config in main.php – Pitchinnate Feb 19 '13 at 18:58
  • @FabianoLothor, the db config is as follows: 'db'=>array( 'connectionString' => 'mysql:host=mysql09.webdomain.dk;dbname=fin*******;', 'emulatePrepare' => true, 'username' => 'fin******', 'password' => '*******', 'charset' => 'utf8' ), If I upload this application to a remote server, gii works with no problem, I just cannot get it to run localy. ipFilter is also set to my ip. – Johhny P Feb 20 '13 at 06:45
  • @Pitchinnate, main.php is not overwriting the db config. – Johhny P Feb 20 '13 at 06:47
  • Can you connect to `mysql09.webdomain.dk` from your local machine? E.g. with a MySQL GUI. – schmunk Feb 20 '13 at 10:37
  • Absolutely, I can connect to it with any browser. – Johhny P Feb 20 '13 at 10:39

2 Answers2

0

Verify your connection the MySQL database, eg. with telnet

$ telnet domain.with-mysql-networking.enabled 3306

Trying 1.2.3.4...
Connected to domain.with-mysql-networking.enabled (1.2.3.4).
Escape character is '^]'.

5.0.51a-24+lenny5o?UnKl\hu7,Nc*CTZI>:H<2

^CConnection closed by foreign host.

If your server does not accept remote connections, you'll see no answer:

$ telnet domain.without-mysql-networking.enabled 3306
Trying 10.9.8.7...
^C

Check this MySQL setting: http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_skip-networking

schmunk
  • 4,708
  • 1
  • 27
  • 50
  • When telneting I get the following error: `Could not open connection to the host on port 3306` So I tried to flush hosts on mysqladmin, but then I get this error: `#1227 - Access denied; you need the RELOAD privilege for this operation` – Johhny P Feb 20 '13 at 11:24
  • I don't think you can fix this with PHPmyAdmin, as you even can't connect to your host. You either have to change the MySQL server config to accept network connections or copy your database to your dev machine. – schmunk Feb 20 '13 at 12:49
  • But I can connect to the database from the very same application when it is hosted on a remote host, I just cannot connect to the db, when running the application localy. – Johhny P Feb 20 '13 at 12:56
  • Yeah, sure. Because if the app runs on the server it connects locally on the server though the socket file, usually without network activity. If you're connecting from your dev machine you do this via TCP/IP - and this is usually disabled by default. – schmunk Feb 20 '13 at 12:59
  • Oh, I understand now, thank you. Can the settings be easily changed? – Johhny P Feb 20 '13 at 13:16
  • Yes, if you have access to my.cnf ... or maybe via a Web Admin Panel. – schmunk Feb 20 '13 at 14:12
0

In gii configs, set:

'ipFilters' => array('*'),
FabianoLothor
  • 2,752
  • 4
  • 25
  • 39
  • tried this, does not work when running localy. If I upload application to a remote host, the connection is alright. – Johhny P Feb 20 '13 at 11:56