Reputation: 429
I'm sure this will be pretty easy, but I've been looking at this for a while, and haven't figured it out yet. I've got a project in Cloud9 that I am trying to set up to access a MySQL database. I've started the MySQL engine (mysql-ctl start), so I don't think that's the issue.
Here are my variables:
$db_hostname = "[username]-[projectname]-[assigned id]"; //this was retrieved by using 'SELECT @@hostname;' within MySQL
$db_database = "c9"; //default cloud9 database
$db_username = "[username]";
$db_password = ""; //the default is no password
$db_port = 3306; //the default cloud9 MySQL port
And here is my mysqli connect statement:
$conn = mysqli_connect($db_hostname, $db_username, $db_password, $db_database, $db_port) or die("Connection failed: " . mysqli_connect_error());
And this is the error that is being sent back:
Warning: mysqli_connect(): (HY000/2002): Connection refused in /home/ubuntu/workspace/insertWorkoutScript.php on line 11
Call Stack:
0.0009 248728 1. {main}() /home/ubuntu/workspace/insertWorkoutScript.php:0
0.0012 249768 2. mysqli_connect() /home/ubuntu/workspace/insertWorkoutScript.php:11
Connection failed: Connection refused
Line 11 (the line that the error identifies) is the $conn = mysqli ...
statement. I've verified that the variables are being filled (I've got an echo for each variable name and it's value). I've double and triple checked the value I'm using for $db_hostname
(which as I said, I retrieved from cloud9 using the SELECT @@hostname;
statement). And as I said, I've made sure to Start the MySQL instance with the $ mysql-ctl start
line in the terminal. Thoughts on what simple thing I'm missing here?
Thanks
Upvotes: 4
Views: 1047
Reputation: 429
Thank you @HPierce for the reminder to try getenv('IP'). I had tried that earlier but got a bad function response. My guess is that I typed it incorrectly, or was using it incorrectly. I've tried that again, and am now getting a good connection. So the correct settings are:
$db_hostname = getenv('IP'); // as opposed to using results from select @@hostname;
$db_database = "c9"; //default cloud9 database
$db_username = "[username]";
$db_password = ""; //the default is no password
$db_port = 3306; //the default cloud9 MySQL port
Everything else stayed the same. And I've also now solved my SQL insertion error as well. Thanks again for your help.
Upvotes: 3