mysql_connect not doing anything at all

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • criveraf
    New Member
    • Feb 2008
    • 3

    mysql_connect not doing anything at all

    Hi there,

    I wasn't sure where to put this question, since it deals with both PHP and MySQL. I apologize if this is not the correct forum for this.

    I am working with a simple PHP application using MySQL at the data layer.

    This is on a Windows XP machine, using IIS 6.0, MySQL 5.0, PHP 5.

    The problem I am having is that a call to mysql_connect is not working, it is not doing anything at all. I'm not getting any error messages, or warnings, or a whistle, or whatever. It just does nothing at all.

    This is the script:

    [PHP]<?php

    $dbConn = mysql_connect(' 127.0.0.1', 'root', 'thepassword') or die('Could not connect: ' . mysql_error());

    echo "HURRAY! mysql_connect works!<br>"; // this line never gets displayed on the page

    if (!$dbConn)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db ("mydb", $dbConn);

    $sql="SELECT * FROM levels";

    $result = mysql_query($sq l);

    echo "<table border='1'>
    <tr>
    <th>levelname </th>
    <th>mingamespla yed</th>
    <th>mingameswon </th>
    </tr>";

    while($row = mysql_fetch_arr ay($result))
    {
    echo "<tr>";
    echo "<td>" . $row['levelname'] . "</td>";
    echo "<td>" . $row['mingamesplayed '] . "</td>";
    echo "<td>" . $row['mingameswon'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";

    mysql_close($db Conn);
    ?>[/PHP]

    I put the line that says [PHP]echo "HURRAY! mysql_connect works!<br>";[/PHP] as a reachmark; however, it never gets displayed, and I am not getting the data requested. All I get is a blank page. I even put a wrong host, username and password to provoke an error, and I don't EVEN get an error.

    MySQL is working. I have created, populated and retrieved data using the tools provided by MySQL. I have created other PHP pages --not using MySQL calls-- and they work just fine.

    I have tried whatever I have read throughout the internet with not success. I have checked the php.ini file for the extensions and extensions_dir, and the place where the libmysql.dll and the php_mysqli.dll should be, etc, etc, etc. But I get nothing, nothing at all.

    I think here's all the info, but if you need something else to help me out, let me know to give you that extra info. You can ask me anything, even if I have tried it, so just in case whatever I have tried I have done it incorrectly.

    Please help, and thanks in advance.

    C
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Do you have error reporting sign.

    When you get a blank page, that's usually a telltale sign that a fatal error has occured and error reporting is not on.

    Check your php.ini file to turn these on, test it by a new PHP file and try to make an error. forget a { or a semicolon. It should warn you.

    Comment

    • criveraf
      New Member
      • Feb 2008
      • 3

      #3
      Nope, nada, zilch, nothing....

      I have the php.ini entries set up for error logging and nothing gets logged.

      What else should I check?

      Comment

      • Nadeem0319
        New Member
        • Feb 2008
        • 5

        #4
        Hey!

        Try This:


        [PHP]
        <?php

        $dbConn = mysql_pconnect( '127.0.0.1', 'root', 'thepassword');
        if (!$dbConn){ die('Could not connect: ' . mysql_error()); }

        echo "HURRAY! mysql_pconnect works!<br>"; // this line should be displayed now

        mysql_select_db ("mydb", $dbConn);

        $sql="SELECT * FROM levels";

        $result = mysql_query($sq l);
        if(!$result){ die mysql_error(); }

        echo "
        <table border='1'>
        <tr>
        <th>levelname </th>
        <th>mingamespla yed</th>
        <th>mingameswon </th>
        </tr>";

        while($row = mysql_fetch_arr ay($result))
        {
        echo "<tr>";
        echo "<td>" . $row['levelname'] . "</td>";
        echo "<td>" . $row['mingamesplayed '] . "</td>";
        echo "<td>" . $row['mingameswon'] . "</td>";
        echo "</tr>";
        }
        echo "</table>";

        mysql_close($db Conn);
        ?>
        [/PHP]

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          Instead of:
          <?php

          $dbConn = mysql_connect(' 127.0.0.1', 'root', 'thepassword') or die('Could not connect: ' . mysql_error());

          echo "HURRAY! mysql_connect works!<br>"; // this line never gets displayed on the page

          if (!$dbConn)
          {
          die('Could not connect: ' . mysql_error());
          }

          mysql_select_db ("mydb", $dbConn);

          $sql="SELECT * FROM levels";

          ..
          Try:
          [PHP]
          mysql_connect(" 127.0.0.1", "root", "thepasswor d") or die('Could not connect to MySQL: ' . mysql_error());
          echo "Connected to MySQL<br />";
          mysql_select_db ("mydb") or die('Could not connect to Database: ' . mysql_error());
          echo "Connected to Database";

          $result = mysql_query("SE LECT * FROM levels") or die('Could not connect to Table: ' . mysql_error());

          [/PHP]

          You were dying twice for some reason (line 3 and 9 or your code) and even though it might work, I am not familiar with the way you wrote it with regards to how you use mysql_select_db and a few others. Then again, I am very new, so maybe everything I have said is a waste of time. If so, let me know and I will shut up!

          Comment

          • Nadeem0319
            New Member
            • Feb 2008
            • 5

            #6
            or you could just try the one i posted :P it has to work :D lol

            Comment

            • criveraf
              New Member
              • Feb 2008
              • 3

              #7
              Many thanks to all who replied.

              All suggestions are good, but they are all the same. In fact, my lines of code were taken from a working example.

              Anyway, I am embarassed to say that it now works and it only required a good old reboot of my machine!! :S

              Although one thing that hint me about doing a reboot was the php.exe shell. I invoked my php page through the shell and it gave me the error messages that were not showing up on the browser. So I corrected them and rebooted.

              TA-DA!

              I leave this information for everyone, so nobody else goes through this embarassment... :-(

              Again, thanks to all who posted!

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by Nadeem0319
                or you could just try the one i posted :P it has to work :D lol
                More than one suggestions are welcome.

                Comment

                Working...