Author Topic: Trouble accessing MySQL database  (Read 1674 times)

0 Members and 1 Guest are viewing this topic.

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Trouble accessing MySQL database
« on: September 01, 2010, 10:14:38 AM »
Hello,

After re-hosting a website there has been trouble connecting to the database.

The MySQL error can be seen here:

http://www.lock-tech.co.uk/home/

If someone can help out with this i would be amazed.

Kind regards,
laanes

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,586
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: Trouble accessing MySQL database
« Reply #1 on: September 01, 2010, 10:18:08 AM »
You do realize that most people on a forum won't click on links you put in your posts.

Just copy/paste the error message into a post to get the quickest solution.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline Pikachu2000

  • I hate everything.
  • Global Moderator
  • Freak!
  • *
  • Posts: 9,050
  • Gender: Male
  • Is it solipsistic in here, or is it just me?
    • View Profile
Re: Trouble accessing MySQL database
« Reply #2 on: September 01, 2010, 10:26:19 AM »
Looks like either the username, or password, or MySQL server host name, or any combination of those are wrong. Check the hosting company's FAQ's, and other docs to make sure you have everything specified correctly.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf * || Linux Help --> linuxforum.com

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Re: Trouble accessing MySQL database
« Reply #3 on: September 01, 2010, 10:35:13 AM »
The error message:


Warning
mysql_connect() [function.mysql-connect]: Access denied for user 'swansea3_locktes'@'localhost' (using passwordYESin /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php on line 25

Warning
mysql_select_db() [function.mysql-select-db]: Access denied for user 'swansea3'@'localhost' (using passwordNOin /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php on line 26

Warning
mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php on line 26

Warning
Cannot modify header information headers already sent by (output started at /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php:25in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 3

Warning
Cannot modify header information headers already sent by (output started at /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php:25in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 4

Warning
Cannot modify header information headers already sent by (output started at /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php:25in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 5

Warning
Cannot modify header information headers already sent by (output started at /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php:25in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/sessions.php on line 6

Warning
mysql_query() [function.mysql-query]: Access denied for user 'swansea3'@'localhost' (using passwordNOin /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php on line 203

Warning
mysql_query() [function.mysql-query]: A link to the server could not be established in /home/swansea3/public_html/lock-tech.co.uk/home/scrptz/functions.php on line 203
ERROR 
{2.1a}! Please navigate to a different page and then try this page again.


I have tried various sets of user names with various different database names/passwords.

The hosting provider says that my connection details are correct and i need to check the configuration in the index.php file. That does not make sense as the website has only been re-hosted, not modified in any way.



Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,586
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: Trouble accessing MySQL database
« Reply #4 on: September 01, 2010, 10:40:39 AM »
As Pikachu2000 wrote, either one of the three pieces of information is wrong or you don't have a database on that hostname setup with permissions for that username/password.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Re: Trouble accessing MySQL database
« Reply #5 on: September 01, 2010, 10:56:06 AM »
Structure of index.php:


<?php 
$hostName
="localhost"
$dbName="*******"$pwd="*******"
@
mysql_connect($hostName$dbName$pwd); 
@
mysql_select_db($dbName); 

function 
clean($input$maxLength){$input=substr(stripslashes(EscapeShellCmd($input)), 0$maxLength); return $input;}
foreach(
$HTTP_GET_VARS as $varName=>$value)$getVars[$varName]=trim(clean($value100)); 
foreach(
$HTTP_POST_VARS as $varName=>$value)$postVars[$varName]=trim(clean($value100));

?>



Is it possible that some of the syntax out of date and is not compatible with the server version?

Offline Pikachu2000

  • I hate everything.
  • Global Moderator
  • Freak!
  • *
  • Posts: 9,050
  • Gender: Male
  • Is it solipsistic in here, or is it just me?
    • View Profile
Re: Trouble accessing MySQL database
« Reply #6 on: September 01, 2010, 11:01:34 AM »
What company is the site hosted with?
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf * || Linux Help --> linuxforum.com

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Re: Trouble accessing MySQL database
« Reply #7 on: September 01, 2010, 11:04:47 AM »
MySQL client version: 5.0.91

Server version: 5.0.91

Server: Localhost via UNIX socket

Offline Pikachu2000

  • I hate everything.
  • Global Moderator
  • Freak!
  • *
  • Posts: 9,050
  • Gender: Male
  • Is it solipsistic in here, or is it just me?
    • View Profile
Re: Trouble accessing MySQL database
« Reply #8 on: September 01, 2010, 11:09:42 AM »
If they provide phpMyAdmin as one of the tools, are you able to log in and use it with the same credentials you're using in the script?
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf * || Linux Help --> linuxforum.com

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Re: Trouble accessing MySQL database
« Reply #9 on: September 01, 2010, 11:19:20 AM »
I am always logged into phpMyAdmin with one default user.

Credentials for each database are set through a database wizard in cPanel but when using phpMyadmin it always shows the default user - defaultuser@localhost, no matter which database is currently being used.
« Last Edit: September 01, 2010, 11:20:07 AM by laanes »

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Re: Trouble accessing MySQL database
« Reply #10 on: September 01, 2010, 11:31:52 AM »
If any helpful, here is the rest of the code in index.php:

<?php $hostName="localhost"
$dbName="****"$pwd="****"
@
mysql_connect($hostName$dbName$pwd); 
@
mysql_select_db($dbName); 

function 
clean($input$maxLength){$input=substr(stripslashes(EscapeShellCmd($input)), 0$maxLength); return $input;}
foreach(
$HTTP_GET_VARS as $varName=>$value)$getVars[$varName]=trim(clean($value100)); 
foreach(
$HTTP_POST_VARS as $varName=>$value)$postVars[$varName]=trim(clean($value100));
if(
$postVars["action"]=="login")
{
	
if(
$postVars["usr"] && $postVars["pwd"])
	
{
	
	
// Get customer details
	
	
if(
$custDetails=mysql_fetch_array(@mysql_query("SELECT * FROM customers WHERE accCode='".$postVars["usr"]."' and password='".$postVars["pwd"]."'")))
	
	
{
	
	
	
$securePrefix="https://fusion.bpweb.net/secure/locktech/";
	
	
	
$navTo=$postVars["goto"]."?uid=".$postVars["uID"];

	
	
	
// Insert details in session table
	
	
	
mysql_query("UPDATE sessions SET accCode='".$custDetails["accCode"].
	
	
	
"', discount='".$custDetails["salesInd3"].
	
	
	
"', buyAlert='".$custDetails["buyAlert"].
	
	
	
"', stockAlert='".$custDetails["stockAlert"].
	
	
	
"', vat='".$custDetails["vat"].
	
	
	
"' WHERE uid='".$postVars["uID"]."' LIMIT 1")
	
	
	
or 
$navTo="login.php?uid=".$postVars["uID"]."&logError=true";
	
	
}
	
	
else
	
	
{
	
	
	
unset(
$securePrefix);
	
	
	
$navTo="login.php?uid=".$postVars["uID"]."&logError=true";
	
	
}
	
}
}
elseif(
$postVars["killSession"]){@mysql_query("DELETE FROM sessions WHERE uid='".$postVars["killSession"]."' AND accCode='".$postVars["account"]."' LIMIT 1"); $navTo="main.php";}
elseif(
$getVars["myURL"])
{
	
if(
strpos($getVars["myURL"], "account")===false && strpos($getVars["myURL"], "basket")===false &&
	
strpos($getVars["myURL"], "checkout")===false &&
	
strpos($getVars["myURL"], "confirm")===false && strpos($getVars["myURL"], "goto")===false && strpos($getVars["myURL"], "vat")===false &&
	
strpos($getVars["myURL"], "PCode")===false && strpos($getVars["myURL"], "qty")===false && strpos($getVars["myURL"], "orders")===false && strpos($getVars["myURL"], "chpwd")===false &&
	
strpos($getVars["myURL"], "price")===false && strpos($getVars["myURL"], "UPDATE")===false && strpos($getVars["myURL"], "DELETE")===false &&
	
strpos($getVars["myURL"], "myURL")===false && strpos($getVars["myURL"], "uid")===false && strpos($getVars["myURL"], "action")===false)
	
{
	
	
$navTo=$getVars["myURL"];
	
	
foreach(
$getVars as $varName=>$value)if($varName!="myURL" && $varName!="goto" && $varName!="vat" && $varName!="PCode" && $varName!="qty" &&
	
	
$varName!="price" && $varName!="UPDATE_x" && $varName!="DELETE_x" && $varName!="uid" && $varName!="action")$navTo.="&amp;".$varName."=".$value;
	
}
	
else{
$navTo="main.php"; unset($securePrefix);}
}
else{
$navTo="main.php"; unset($securePrefix);} ?>

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Re: Trouble accessing MySQL database
« Reply #11 on: September 01, 2010, 11:36:20 AM »
I just noticed that URL does not exist:

$securePrefix="https://fusion.bpweb.net/secure/locktech/";

Quote
The requested URL /secure/locktech/ was not found on this server.

But even if i remove it nothing changes so I guess that hasn't got nothing to do with it.
« Last Edit: September 01, 2010, 11:45:26 AM by laanes »

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,586
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: Trouble accessing MySQL database
« Reply #12 on: September 01, 2010, 11:44:39 AM »
Quote
@mysql_connect($hostName, $dbName, $pwd);
@mysql_select_db($dbName);

^^^ If that's your real code, take a look at it. You are using $dbName as the mysql username (2nd parameter in the mysql_connect.) Edit: And I'm going to guess that if you had actually read the mysql_connect() error message, you would have noticed that the user it mentions is actually your database name? You are the only one here who knows what your actual information is and can interpret what the error message means relative to what you are doing.

And I'm guessing that the @'s in the code were just put there by you due to the error messages?

Hiding the errors won't make your code work. It still won't work AND there won't be any error messages to tell you why it is not working.
« Last Edit: September 01, 2010, 11:53:39 AM by PFMaBiSmAd »
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

Offline laanesTopic starter

  • Enthusiast
  • Posts: 70
    • View Profile
Re: Trouble accessing MySQL database
« Reply #13 on: September 01, 2010, 12:04:07 PM »
Quote
You are the only one here who knows what your actual information is and can interpret what the error message means relative to what you are doing.

$hostName="localhost";
$dbUser="swansea3_lockT";
$dbName="swansea3_locktest";


Quote
And I'm guessing that the @'s in the code were just put there by you due to the error messages?

Hiding the errors won't make your code work. It still won't work AND there won't be any error messages to tell you why it is not working.

Code has not been written by me, if it would, i would not be asking questions here.

I have removed the @'s and changed the parameters in mysql_connect:


$hostName
="localhost"
$dbName="swansea3_locktest"
$dbUser="swansea3_lockT";
$pwd="******"
mysql_connect($hostName$dbUser$pwd); 
mysql_select_db($dbName); 


Error message does not change.

I don't get why the error message is saying Access denied for user 'swansea3'@'localhost as I have not swansea3 to be a user for that database.

swansea3 is the default username given you when creating an account with the hosting provider and is also the database prefix.
« Last Edit: September 01, 2010, 12:11:00 PM by laanes »

Offline PFMaBiSmAd

  • Guru
  • 'Insane!'
  • *
  • Posts: 14,586
  • In Coding, Automatic means you write code to do it
    • View Profile
Re: Trouble accessing MySQL database
« Reply #14 on: September 01, 2010, 01:04:20 PM »
There's no way the code you have been posting with the @'s in it could have been outputting the posted errors. You must have some other code at the file/line number being reported in the errors.

Only the first error is relevant to this problem. The other errors are follow-on errors caused because the mysql_connect() is failing.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.