MySQL cannot connect to database
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Re: MySQL cannot connect to database
MySQL cannot connect to database
30-12-2016 8:04 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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.
Re: MySQL cannot connect to database
30-12-2016 9:21 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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 ⤵
Re: MySQL cannot connect to database
01-01-2017 10:04 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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
Re: MySQL cannot connect to database
02-01-2017 1:08 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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?
Re: MySQL cannot connect to database
04-01-2017 10:23 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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
Re: MySQL cannot connect to database
05-01-2017 7:26 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
@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?
Re: MySQL cannot connect to database
05-01-2017 11:06 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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>
Re: MySQL cannot connect to database
05-01-2017 12:13 PM - edited 05-01-2017 12:14 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Re: MySQL cannot connect to database
05-01-2017 1:25 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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?
Re: MySQL cannot connect to database
05-01-2017 1:57 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Well spotted @spraxyt, totally missed that!
Re: MySQL cannot connect to database
05-01-2017 5:31 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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
Re: MySQL cannot connect to database
05-01-2017 7:39 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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.
Re: MySQL cannot connect to database
05-01-2017 7:44 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Are you actually doing this test on the Hostopia ccgi server? Mentioning those PHP versions suggests to me it's 123-reg.
Re: MySQL cannot connect to database
05-01-2017 9:08 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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
Re: MySQL cannot connect to database
05-01-2017 9:56 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
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?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- Re: MySQL cannot connect to database