1

I am attempting to connect to a mysql database using the c9.io development environment. I have followed their documentation and have seen multiple links, 1, 2 and 3.

I verified the mysql service is running. I also verified the PDO extension was installed via phpinfo(). Here is my current code:

$ip = getenv("REMOTE_ADDR");
$port = '3306';
$user = "username";
$db = "c9";

    try{
    $con = new PDO("mysql:host=$ip;port=$port;dbname=$db;charset=utf8",$user,"");
    }
    catch(Exception $e){
        echo $e->getMessage();
    }

I get the error Can't connect to MySQL server on '10.240.x.x' (111)

If i try localhost as host, I get the error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I also followed a comment from the second link above: echo $IP in the terminal which returns 0.0.0.0

Any assistance appreciated.

Community
  • 1
  • 1
andrsnn
  • 1,591
  • 5
  • 25
  • 43

1 Answers1

2

You were on the right track. On https://docs.c9.io/setting_up_mysql.html it says use $IP for host. You can use getenv("IP") instead or use its value: 0.0.0.0. That should work. Please try something like:

$dbname = 'c9';
$ip = getenv('IP');
$user = getenv('C9_USER');

mysql_connect($ip, $user, '') or die('Could not connect to mysql');
basdw
  • 486
  • 2
  • 1