Using PHP to connect to MySQL

Discussion in 'HTML / PHP / JavaScript / CSS' started by Athelene, Jan 12, 2014.

  1. I am trying to use PHP to connect to a MySQL database. I have used the sample code provided in the knowledge base (changing the host, user, password and database to match my information of course) and I get an error that reads "Could not connect: Can't connect to MySQL server on 'mysql502.discountasp.net' (4)". The code I'm using is below. Unfortunately, the knowledge base points me to the forum if Disount ASP.NET's own sample code doesn't work. (Seems like pretty lousy support to say that they won't help you if they can't even produce a simple example of how to connect. But that's another story.) Can someone please help me to figure out why my connection is failing?

    Code (taken directly from the KB and modified with my credentials hidden here with asterisks):

    <h1>MySQL Test Code Results</h1>
    <p />
    <table border="1">
    <tr>
    <td>
    pkID
    </td>
    <td>
    username
    </td>
    <td>
    password
    </td>
    </tr>
    <?php
    // Configuration Information and Definitions
    $mysql_host = '*******.discountasp.net';
    $mysql_user = '*******';
    $mysql_pass = '*******';
    $mysql_db = '*******';
    $query = 'SELECT * from *******';
    mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die("Connection to MySQL-server failed!");
    mysql_select_db($mysql_db) or die("Selection of database $mysql_db failed!");
    $result = mysql_query($query) or die("Invalid Query, " . mysql_error());
    while( list( $pkid, $user, $pass ) = mysql_fetch_row($result) ) {
    printf("<tr><td>%d</td><td>%s</td><td>%s</td></tr>", $pkid, $user, $pass);
    }
    ?>
    </table>
    <p />
    <b>End MySQL Test Code Results</b>
     
  2. RayH

    RayH DiscountASP.NET Lackey DiscountASP.NET Staff

    You can open up a support ticket so we can check the connection problem, however, we just can't provide programming support. If our sample code isn't working, we'll at least get that working for you.
     
  3. I'm having the same problem...but looks like nobody wants to reply...Oopps!
    They force the upgrade, but then don't help with coding???
    HELP!!!
     
  4. Athelene, if you could provide a link to your site so that we can see this code failing to connect to your database it would be much appreciated.

    Wmc531 you have already opened another thread for your connection issue and we will take a look at your connection problems in that thread.
     
  5. mjp

    mjp

    Sorry about that. Trust me though, we wouldn't force any server or O/S migration if we didn't have to. We don't like to put you guys through it. It's no fun for either of us.

    Unfortunately, Windows being Windows, the older a given version of the O/S gets, the more security issues crop up. And after the product's "end-of-life," Microsoft won't fix those issues. So the alternative to forcing migration is ignoring the problems and letting our users host their sites on an insecure platform. It wouldn't be very responsible of us to do that (and it wouldn't be good for our network), so we don't.
     

Share This Page