/    Sign up×
Community /Pin to ProfileBookmark

Connecting to MySQL Database problems.

Hi all,
Ok so I am very new to PHP and have been following numerous tutorials in making user registration and login possible on a personal project I am working on. The issue I have is that every time I enter my hostname, database name, password and other info it fails every time. In every tutorial the person connects to the local database they have created where as mine is set up on the web via my GoDaddy Hosting Account. I also don’t understand why they all do this to a local host database as any forms filled in on the hosting account server won’t go to their database on their computer, right? Hopefully my question isn’t too stupid and I find an answer.

Thanks,
Jamie

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@rootNov 24.2013 — Well it would help if you provide the code you are using to connect to your server, we don't need to know anything sensitive like server or login names, etc, it will be taken for granted that you have these set up correctly, what members helping will need to know is the actual code you are using.

Some servers will require the use of the connection handle, especially where the user is using a database on a shared server that is handling several hundred connections.
Copy linkTweet thisAlerts:
@jamiemcukauthorNov 24.2013 — Here is the code:

<?php

session_start();

$exceptions = array('signup', 'signin');

$page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4);

if (in_array($page, $exceptions) === false){

if (isset($_SESSION['username']) === false){

header('Location: signin.php');

die();

}

}

mysql_connect('hostname', 'mysql username', 'password');

mysql_select_db('mysql database name');

$path = dirname(__FILE__);

include("{$path}/inc/user.inc.php");

?>

The error I get when submitting or now loading the signup page is -

Warning: mysql_connect() [function.mysql-connect]: [2002] Connection refused (trying to connect via tcp://psusersdb.db.10497025.hostedresource.com:3306) in /Users/jamiemcardle/Sites/Personal Statment/core/init.inc.php on line 16

Warning: mysql_connect() [function.mysql-connect]: Connection refused in /Users/jamiemcardle/Sites/Personal Statment/core/init.inc.php on line 16

Warning: mysql_select_db() [function.mysql-select-db]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/jamiemcardle/Sites/Personal Statment/core/init.inc.php on line 17

Warning: mysql_select_db() [function.mysql-select-db]: No such file or directory in /Users/jamiemcardle/Sites/Personal Statment/core/init.inc.php on line 17

Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /Users/jamiemcardle/Sites/Personal Statment/core/init.inc.php on line 17

Warning: include(/Users/jamiemcardle/Sites/Personal Statment/core/inc/user.inc.php) [function.include]: failed to open stream: No such file or directory in /Users/jamiemcardle/Sites/Personal Statment/core/init.inc.php on line 21

Warning: include() [function.include]: Failed opening '/Users/jamiemcardle/Sites/Personal Statment/core/inc/user.inc.php' for inclusion (include_path='.:') in /Users/jamiemcardle/Sites/Personal Statment/core/init.inc.php on line 21
Copy linkTweet thisAlerts:
@rootNov 25.2013 — [code=php]mysql_connect('hostname', 'mysql username', 'password');
mysql_select_db('mysql database name');[/code]


[code=php]$handle = mysql_connect('hostname', 'mysql username', 'password');
mysql_select_db('mysql database name',$handle);[/code]


The problem seems that your on a shared resource and need to use a link identifier AKA a handle.

You should also upgrade to mysqli or PDO connection methods because PHP will be dropping support for those older methods of connection to a database.

Seems the old saying "If it aint broke" seems to be falling on deaf ears.
×

Success!

Help @jamiemcuk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...