php to mysql connection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • obmij
    New Member
    • May 2007
    • 3

    php to mysql connection

    Hi all,
    I am a WAMP newbie and would appreciate your help! I have installed Apache 2.2.4, Mysql 5 and PHP 5 have got them all up and running and tested them separately, I was able to do the info.php test to display environment variables in a browser successfully. I tried to test a connection to mysql using the following code:

    [code=html]
    <html>
    <head>
    <title>mysql connection test</title>
    </head>
    <body>
    <h2>
    <p>Testing now!</p>
    <?php
    $dbhost = 'localhost';
    $dbuser = '**********';
    $dbpass = '**********';

    $connection = mysql_connect($ dbhost, $dbuser, $dbpass)
    or die ("Sorry - unable to connect" . mysql_error());

    echo ("Congrats - connection established");
    ?>
    </h2>
    </body>
    </html>
    [/code]

    [Please use CODE tags when posting source code. Thanks! --pbmods]

    which is I understand is fairly standard code to test a connection with (the **** fields actually contain my username and password :)

    When i run this through a browser all I get returned is the "Testing now!" from the html - no errors - nothing!

    I do have error reporting turned on in the php.ini file (error_reportin g = E_ALL & ~E_NOTICE)
    Any ideas people??

    thanks,
    obmij
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, obmij. Welcome to TSDN!

    Originally posted by obmij
    I do have error reporting turned on in the php.ini file (error_reportin g = E_ALL & ~E_NOTICE)
    You have error reporting turned on... but where do the errors get reported? Do you have display_errors turned on, or is it writing them to your server's error log?

    Also, check the source of the page you're loading. Is your PHP code getting parsed, or is it just getting output? If your code is in a .html file, try changing the extension to .php instead.

    Comment

    • obmij
      New Member
      • May 2007
      • 3

      #3
      Originally posted by pbmods
      Heya, obmij. Welcome to TSDN!



      You have error reporting turned on... but where do the errors get reported? Do you have display_errors turned on, or is it writing them to your server's error log?

      Also, check the source of the page you're loading. Is your PHP code getting parsed, or is it just getting output? If your code is in a .html file, try changing the extension to .php instead.

      Thanks for such a speedy reply!
      display_errors was off so i have uncommented that line. Now when i run the above file (which is a .php file) i get the following error:

      "Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apac he2.2\htdocs\my sql_test.php on line 13"

      which would seem to indicate that php cannot find the mysql function even though i have uncommented the "php_mysql. dll" extension in the php.ini file.
      I have also edited the "extension_ dir" variable in the php.ini file to read:
      extension_dir = "C:\Program Files\PHP"
      Curiously when I run the phpinfo() file it still reports the "extension_ dir" as being C:\php5 (and the php.ini path as being C:\windows) - which they definitely are not!

      I have been reading around these problems - they seem to be quite common for WAMP installations but a lot of the solutions seem to contradict one another.
      I am thoroughly confused!!

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        I would suggest using one of the various packaged installers for Apache, MySQL, PHP on the windows platform. WAMP5 and Netserver come with my strong recommendation.

        Comment

        • obmij
          New Member
          • May 2007
          • 3

          #5
          Originally posted by Motoma
          I would suggest using one of the various packaged installers for Apache, MySQL, PHP on the windows platform. WAMP5 and Netserver come with my strong recommendation.

          Thanks for the advice - I downloaded WAMP5 and it works just fine!

          Comment

          Working...