PDA

View Full Version : Problem connecting mysql to localhost


satsujin
07-29-2008, 05:11 PM
Can someone please help with the following problem?
I just installed Apache 2.2.9 and php 5.2.6. I already had mySQL 5.0 installed on the system. Apache and PHP seemed to install okay and a simple PHP file to print text works fine. I can also connect to the mySQL server via the localhost through the mysql cmdline console. However , the following PHP code only displays "hello " :

<HTML>
<HEAD>
<TITLE>DB</TITLE>
</HEAD>
<BODY>

<?php
echo "Hello";
mysql_connect("localhost", "root", "passwd") or die(mysql_error());
echo "Connected<BR>";

?>
</BODY>
</HTML>

abduraooft
07-29-2008, 05:16 PM
Have a try by adding a statement error_reporting(E_ALL); before echoing "Hello".

satsujin
07-29-2008, 05:25 PM
Gave it a shot but still the same output. I think I should add that Microsoft SQL Server was also running on the system but i disabled it.

CFMaBiSmAd
07-29-2008, 05:42 PM
It is likely that the mysql extension is not loaded and that the display_errors setting is off, preventing you from seeing any php generated errors. Add both the following lines after your first opening <?php tag -

ini_set ("display_errors", "1");
error_reporting(E_ALL);

satsujin
07-29-2008, 06:37 PM
Thanks, that managed to throw this out:

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\people2.php on line 11

So, obviously I haven't made the link between mysql and PHP. Is there a site that reliably shows how to get this done? I've heard it's no simple task.

abduraooft
07-29-2008, 06:39 PM
I'd recommend xampp (http://www.apachefriends.org/en/xampp.html) which is pretty easy to deal with.

CFMaBiSmAd
07-29-2008, 06:56 PM
On Windows, if php has been installed correctly, all you normally need to do is uncomment the line in php.ini for the mysql extension dll and restart your web server to get any change made to php.ini to take effect.

satsujin
07-29-2008, 07:42 PM
Well, the xampp installation seems to have resolved the issue. Thanks to everyone for their suggestions and help!