By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,615 Members | 1,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,615 IT Pros & Developers. It's quick & easy.

php to mysql connection

P: 3
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:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>mysql connection test</title>
  4. </head>
  5. <body>
  6. <h2>
  7. <p>Testing now!</p>
  8. <?php
  9. $dbhost = 'localhost';
  10. $dbuser = '**********';
  11. $dbpass = '**********';
  12.  
  13. $connection = mysql_connect($dbhost, $dbuser, $dbpass)
  14. or die ("Sorry  - unable to connect" . mysql_error());
  15.  
  16. echo ("Congrats - connection established");
  17. ?>
  18. </h2>
  19. </body>
  20. </html>
  21.  
[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_reporting = E_ALL & ~E_NOTICE)
Any ideas people??

thanks,
obmij
May 26 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
Heya, obmij. Welcome to TSDN!

I do have error reporting turned on in the php.ini file (error_reporting = 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.
May 26 '07 #2

P: 3
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\Apache2.2\htdocs\mysql_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!!
May 26 '07 #3

Motoma
Expert 2.5K+
P: 3,235
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.
May 26 '07 #4

P: 3
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!
May 28 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.