Error connecting mysql database...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas1111
    New Member
    • Feb 2008
    • 122

    Error connecting mysql database...

    Hi All

    I installed PHP 5.2.5 and MySQL 5.0.51 versions. I am trying to establish the database connection with MySQL through PHP, I got the fatal error of the below message. I am using the IIS server of Windows XP systems with Service pack S2.

    Fatal error: Call to undefined function mysql_connect()

    This is my program, please check it and suggest it.
    [CODE=PHP]
    <?
    $hostname="loca lhost";
    $user="root";
    $pass="root";
    $connection = mysql_connect(" $hostname" , "$user" , "$pass");
    $db = mysql_select_db ($dbase , $connection);
    echo "got the connection";
    ?>
    [/CODE]
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You most probably have simply installed the 2 applications apart from each other and you not installed the MySQL extension in PHP. See your PHP and MySQL installation guidelines on this.

    Ronald

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Like Ronald says, your PHP installation is missing the MySQL extension.

      A common reason for extensions failing to load on Windows is that the PHP install directory is missing from the PATH env variable.

      Try adding that, reboot and try again.

      Comment

      • vikas1111
        New Member
        • Feb 2008
        • 122

        #4
        Hi All

        I installed PHP and MySQL . I am trying to establish the database connection with MySQL through PHP, I got the fatal error of the below message. I am using the MySQL server of Windows XP systems with Service pack S2.

        Fatal error: Call to undefined function mysql_connect()

        This is my program, please check it and suggest it.
        [CODE=PHP]
        <?
        $hostname="loca lhost";
        $user="root";
        $pass="root";
        $connection = mysql_connect(" $hostname" , "$user" , "$pass");
        $db = mysql_select_db ($dbase , $connection);
        echo "got the connection";
        ?>
        [/CODE]
        Last edited by vikas1111; May 7 '08, 07:33 AM. Reason: FORGOT TO ADD <CODE>

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          This has nothing to do with your php code! It is your iunstallation of the PHP and MySQL packages where the problem is.

          See Atli's and my previous posts on this problem. And check your installation of both applications.

          Ronald

          Comment

          • vikas1111
            New Member
            • Feb 2008
            • 122

            #6
            Originally posted by Atli
            Like Ronald says, your PHP installation is missing the MySQL extension.

            A common reason for extensions failing to load on Windows is that the PHP install directory is missing from the PATH env variable.

            Try adding that, reboot and try again.



            Fine.. How can i set path to mysql in PHP or how to check that PHP is missing MySQL extension or not ??.. Should i reinstall PHP ???

            Comment

            • rpnew
              New Member
              • Aug 2007
              • 189

              #7
              Originally posted by vikas1111
              Fine.. How can i set path to mysql in PHP or how to check that PHP is missing MySQL extension or not ??.. Should i reinstall PHP ???
              Hi,
              i think you'll get the information regarding MySql extension in phpinfo()

              Regards,
              RP

              Comment

              • vikas1111
                New Member
                • Feb 2008
                • 122

                #8
                Originally posted by rpnew
                Hi,
                i think you'll get the information regarding MySql extension in phpinfo()

                Regards,
                RP

                Thanks.. But how can i make changes ?

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #9
                  Originally posted by vikas1111
                  Thanks.. But how can i make changes ?
                  Try this...
                  1. Right click on My Computer -> Select Properties
                  2. Select the Advanced tab and click the Environmental Variables button
                  3. Find and double-click the PATH variable in the System Variables list
                  4. Add the absolute path to your PHP installation directory to the the Variable Value. Remember to separate it from the previous item with a semi-colon (;)
                  5. Click OK -> OK and reboot your computer.
                  6. Check if the MySQL extension is working now.

                  Comment

                  • vikas1111
                    New Member
                    • Feb 2008
                    • 122

                    #10
                    Originally posted by Atli
                    Try this...
                    [*]Find and double-click the PATH variable in the System Variables list[*]Add the absolute path to your PHP installation directory to the the Variable Value. Remember to separate it from the previous item with a semi-colon (;)
                    [/list]


                    Thanks..
                    This.. %SystemRoot%\sy stem32;%SystemR oot%;%SystemRoo t%\System32\Wbe m;C:\Program Files\Microsoft SQL Server\80\Tools \BINN..
                    Is already there in the Variable Value field.. Is it correct ???

                    Comment

                    • rpnew
                      New Member
                      • Aug 2007
                      • 189

                      #11
                      Originally posted by vikas1111
                      Thanks..
                      This.. %SystemRoot%\sy stem32;%SystemR oot%;%SystemRoo t%\System32\Wbe m;C:\Program Files\Microsoft SQL Server\80\Tools \BINN..
                      Is already there in the Variable Value field.. Is it correct ???
                      Hi,
                      Leave them as it is you just need to append your mysql path as 'Atli' has suggested.

                      Regards,
                      RP

                      Comment

                      • vikas1111
                        New Member
                        • Feb 2008
                        • 122

                        #12
                        Originally posted by Atli
                        Try this...
                        1. Right click on My Computer -> Select Properties
                        2. Select the Advanced tab and click the Environmental Variables button
                        3. Find and double-click the PATH variable in the System Variables list
                        4. Add the absolute path to your PHP installation directory to the the Variable Value. Remember to separate it from the previous item with a semi-colon (;)
                        5. Click OK -> OK and reboot your computer.
                        6. Check if the MySQL extension is working now.


                        Hi tried but still not working...

                        Comment

                        • Atli
                          Recognized Expert Expert
                          • Nov 2006
                          • 5062

                          #13
                          Originally posted by vikas1111
                          Hi tried but still not working...
                          Check the ext folder in your PHP install dir.
                          "C:\Program Files\PHP\ext" by default.

                          There should be a file called 'php_mysql.dll' .
                          If it is missing you need to run the PHP installer again and have it install the MySQL extension.

                          If that doesn't work, try opening your php.ini file and locate the line starting with 'extension_dir' ...
                          Make sure that this contains the full path to your PHP extension directory.
                          Which, by default, is:
                          Code:
                          extension_dir ="C:\Program Files\PHP\ext"
                          And always remember to restart your HTTP server after making changes.
                          If your using IIS, you will probably have to reboot for the changes to take effect.

                          Comment

                          Working...