dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Connecting to MySQL Database problems.

  1. #1
    Join Date
    Nov 2013
    Posts
    3

    Question 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

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,727
    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.
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Nov 2013
    Posts
    3
    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

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,727
    PHP Code:
    mysql_connect('hostname''mysql username''password');
    mysql_select_db('mysql database name'); 
    PHP Code:
    $handle mysql_connect('hostname''mysql username''password');
    mysql_select_db('mysql database name',$handle); 
    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.
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles