Problem Connecting to MySQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sabrey9600
    New Member
    • Sep 2006
    • 6

    #1

    Problem Connecting to MySQL

    I have problem to connect mysql

    i have database created as dbmail
    i created table field, id (auto and primary key Id), name and email

    then, i used php script to connect...

    <?php

    $connect = mysql_connect(' localhost', 'root', 'mypassword');

    echo $connect;

    ?>

    The reason i do this script, i want to know whether my php is connected or not...
    it is supposed appeared like this "Resource id#1" ( I assumed because i refer to a book from SAMS Teach yourself

    however, it creates blank page in the browser...


    what is wrong? can you tell me....
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You would be better off using

    [php]
    <?php
    $connect = mysql_connect(' localhost', 'root', 'mypassword');
    if (!$connect)
    {
    echo "Connection Failed: " . mysql_error();
    }
    ?>[/php]

    Comment

    • sabrey9600
      New Member
      • Sep 2006
      • 6

      #3
      Originally posted by Banfa
      You would be better off using

      [php]
      <?php
      $connect = mysql_connect(' localhost', 'root', 'mypassword');
      if (!$connect)
      {
      echo "Connection Failed: " . mysql_error();
      }
      ?>[/php]
      I already tried the script you gave me, but it still give me the blank page in the browser...

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        That is good! From the code you see that you only get a message when the connection is not established.
        When you also want a message when the connection is established, add the following code lines to to your script.
        [PHP]else {
        echo "Congratulation s, you are connected";
        }[/PHP]

        Ronald :cool:

        Comment

        • sabrey9600
          New Member
          • Sep 2006
          • 6

          #5
          Originally posted by ronverdonk
          That is good! From the code you see that you only get a message when the connection is not established.
          When you also want a message when the connection is established, add the following code lines to to your script.
          [PHP]else {
          echo "Congratulation s, you are connected";
          }[/PHP]

          Ronald :cool:
          I still got problems on that...

          i still confused... i used php 5.1.4, do i have to enable the mysql in php.ini...?
          it seems that my apache web server is running and mysql is also working properly here...

          can anyone tell me, do i have to use ODBC to connect mysql...?

          I am lost rite now...

          Comment

          • frank74
            New Member
            • Oct 2006
            • 1

            #6
            I had the exact same problem and managed to solve it by searching for all "php.ini" files on my system (WinXP). Windows showed me a php.ini file in "apache/php". I erased that file and all was working fine. Good luck.

            Comment

            • reson
              New Member
              • Jul 2007
              • 1

              #7
              I'm having the same problem, a blank screen with i try to connect to the mysql database. If this is a problem with the php.ini file, where should the php.ini file be located? Right now I have it in the Apache2.2 folder. Is that the correct location for php.ini? Thank you

              Comment

              • kovik
                Recognized Expert Top Contributor
                • Jun 2007
                • 1044

                #8
                When you connect to a database, there is no extra screen shown or confirmation message.. You're just connected. If you are testing locally, and you haven't started MySQL, then the database connection will fail.

                Comment

                Working...