cancel
Showing results for 
Search instead for 
Did you mean: 

MySQL cannot connect to database

csiatst
Dabbler
Posts: 13
Thanks: 4
Registered: ‎30-12-2016

MySQL cannot connect to database

Hi,

I have just got back into my CGI site after a few years and notice that everything has changed. I've now gone from Rumpus server to sql5c51a.megasqlservers.eu

I am trying to use the following connection strings.

 

$database_host = "sql5c51a.megasqlservers.eu";
$database_name = "stephenthompson_pn_ccgi_stephenthompson_plus_com";
$database_username = "ccgi*********";
$database_password = "***********";

But every time I try to access the data I get "Cannot connect".

I can't see what it is that I am doing wrong.

 

 

22 REPLIES 22
bobpullen
Community Gaffer
Community Gaffer
Posts: 16,887
Thanks: 4,979
Fixes: 316
Registered: ‎04-04-2007

Re: MySQL cannot connect to database

Try logging into the control panel at https://hosting.plus.net

Initiate a password reset using ccgi.stephenthompson.plus.com as your username if you're unsure of what it is.

There's an SQL manager in the control panel where you can check the database name/server and set a new password if needs be.

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵

csiatst
Dabbler
Posts: 13
Thanks: 4
Registered: ‎30-12-2016

Re: MySQL cannot connect to database

Bob,

I did this, but I still cannot get it to work. I also created a new database and set up the table in this database. I changed the connection strings to match, but still I cannot connect. I'm sure that this is not a big problem, but I just do not understand where I'm going wrong.

Stephen

spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: MySQL cannot connect to database

Have you set the following lines in /public/.htaccess to ensure any PHP errors or warnings are printed?

php_value display_errors 1
php_value error_reporting 32767

Do you get any error messages when these are present?

Are you using your own code to connect to MySQL or a package such as WordPress?

David
csiatst
Dabbler
Posts: 13
Thanks: 4
Registered: ‎30-12-2016

Re: MySQL cannot connect to database

David,

 

I put the two lines in as you suggested, but I don't get anything different from 'Cannot Connect'.
I'm using my own code which had previously worked until I moved to this new platform and the database names etc. changed their names.

 

Stephen

Anonymous
Not applicable

Re: MySQL cannot connect to database

@csiatst - As you are using your own code can we assume that the ‘Cannot Connect’ message is generated using your own code’s error handler construct? Are you able to post the PHP code you are using please?

csiatst
Dabbler
Posts: 13
Thanks: 4
Registered: ‎30-12-2016

Re: MySQL cannot connect to database

Mook,

Below is the code I have. Obviously I have amended the name, user and password.

<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ClassicFM CD</title>
</head>
<link rel="stylesheet" href="z_steve.css" type="text/css" >
<body text=#FFFFFF background="z_steve_bg_red.gif">
<?php
// require 'db.inc';

$database_host = "sql5c51a.megasqlservers.eu";
$database_name = "Stephen_ccgi************";
$database_username = "ccgi************";
$database_password = "a password - not this";

// Show the CD's in an HTML <table>
function displayCD($result)
{

print "<div align=\"center\"><h1 class=\"pageName\">ClassicFM CD's by $_POST[composer]</h1></div>\n";
//print "class=\"bodyText\""
// Start a table, with column headers

print "\n<table border=\"1\" bordercolor=\"#FF9900\" align=\"center\" class=\"steve\">\n" .
"\n\t<th>Disc</th>" .
"\n\t<th>Suffix</th>" .
"\n\t<th>Track</th>" .
"\n\t<th>Title</th>" .
"\n\t<th>Movement</th>" .
"\n\t<th>Artist 1</th>" .
"\n\t<th>Artist 2</th>" .
"\n\t<th>Artist 3</th>" .
"\n\t<th>Orchestra</th>" .
"\n\t<th>Conductor</th>" .
"\n\t<th>Time</th>" .
"\n</tr>";

// Until there are no rows in the result set, fetch a row into
// the $row array and ...
while ($row = @ mysql_fetch_row($result))
{
// ... start a TABLE row ...
print "\n<tr>";

// ... and print out each of the attributes in that row as a
// separate TD (Table Data).
foreach($row as $data)
print "\n\t<td><span> {$data}</span> </td>";

// Finish the row
print "\n</tr>";
}

// Then, finish the table
print "\n</table>\n";
}

$query = "SELECT Disc, Suffix, Track, Title, Movement, Artist_1, Artist_2, Artist_3, Orchestra, Conductor, Time FROM cd where composer = '$_POST[composer]'";

// Connect to the MySQL server
// Connect to the MySQL server
if (!($connection = @ mysql_connect($hostName, $username, $password)))
die("Cannot connect");

if (!(mysql_select_db($databaseName, $connection)))
showerror();

// Run the query on the connection
if (!($result = @ mysql_query ($query, $connection)))
showerror();

// Display the results
displayCD($result);
?>
</body>
</html>

Anonymous
Not applicable

Re: MySQL cannot connect to database

@csiatst, thanks for that, I don't know what version of PHP comes with your CGI package but you may find this of interest whether it is related is of course is another matter. But as you're suppressing your errors you may never know, so you might want to dispense with the @ symbol while you debug.

spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: MySQL cannot connect to database

PHP on ccgi is version 5.3 so the original mysql API functions, though discouraged should still work. Replacing the die("Cannot connect"); code with

die ('Could not connect to the database server:<br />' . mysql_error());

should display the reason for failing to connect.

However is this that the PHP variables providing the connection and database properties are named differently from those in the MySQL calls?

David
Anonymous
Not applicable

Re: MySQL cannot connect to database

Well spotted @spraxyt, totally missed that!

csiatst
Dabbler
Posts: 13
Thanks: 4
Registered: ‎30-12-2016

Re: MySQL cannot connect to database

Mook,

 

I have changed the die as suggested.

I now get :-

 

Could not connect to the database server:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

 

I will look at this this evening if I get the chance. Currently just about to leave work.

 

Stephen

csiatst
Dabbler
Posts: 13
Thanks: 4
Registered: ‎30-12-2016

Re: MySQL cannot connect to database

The version of PHP I'm using is 5.2, but I can change this to 5.3 or 5.6 if that would help.

spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: MySQL cannot connect to database

Are you actually doing this test on the Hostopia ccgi server? Mentioning those PHP versions suggests to me it's 123-reg.

David
csiatst
Dabbler
Posts: 13
Thanks: 4
Registered: ‎30-12-2016

Re: MySQL cannot connect to database

David,

It's on the PlusNet service. It used to use thier Rumpus server, but it changed a whiile ago and I've just got round to trying to look at my site again after a long time. I also use a Genealogy package on it as well (which has the same problem). But I want to get this little query working again first. All is does is look up a composer and then list all the CD tracks that are by that composer. There is only one table at the moment, so it's really, really simple.

Stephen

spraxyt
Resting Legend
Posts: 10,063
Thanks: 674
Fixes: 75
Registered: ‎06-04-2007

Re: MySQL cannot connect to database

Stephen,

What puzzled me was mentioning changing the PHP version. How do you change that on ccgi? As far as I'm aware it's 5.3.x unless Hostopia update it.

Unfortunately the error message you got with the amended "die" statement doesn't get diagnostics much further. I also asked if your real code sets these PHP variables

$database_host = "sql5c51a.megasqlservers.eu";
$database_name = "Stephen_ccgi************";
$database_username = "ccgi************";
$database_password = "a password - not this";

then uses different variable names with the connection and db selection code

if (!($connection = @ mysql_connect($hostName, $username, $password)))
die("Cannot connect");
if (!(mysql_select_db($databaseName, $connection)))
showerror();

 Did you check that?

David