Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Error connecting mysql database...

Question posted by: vikas1111 (Member) on May 6th, 2008 12:40 PM
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: ( text )
  1. <?
  2. $hostname="localhost";
  3. $user="root";
  4. $pass="root"; 
  5. $connection = mysql_connect("$hostname" , "$user" , "$pass");
  6. $db = mysql_select_db($dbase , $connection);
  7. echo "got the connection";
  8. ?>
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
ronverdonk's Avatar
ronverdonk
Moderator
4,138 Posts
May 6th, 2008
04:10 PM
#2

Re: Error connecting mysql database...
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
__________________
RTFM is an almost extinct art form.

Reply
Atli's Avatar
Atli
Moderator
1,866 Posts
May 7th, 2008
01:35 AM
#3

Re: Error connecting mysql database...
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.

Reply
vikas1111's Avatar
vikas1111
Member
105 Posts
May 7th, 2008
07:30 AM
#4

Re: Error connecting mysql database...
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: ( text )
  1. <?
  2. $hostname="localhost";
  3. $user="root";
  4. $pass="root";
  5. $connection = mysql_connect("$hostname" , "$user" , "$pass");
  6. $db = mysql_select_db($dbase , $connection);
  7. echo "got the connection";
  8. ?>

Last edited by vikas1111 : May 7th, 2008 at 07:33 AM. Reason: FORGOT TO ADD <CODE>
Reply
ronverdonk's Avatar
ronverdonk
Moderator
4,138 Posts
May 7th, 2008
08:44 AM
#5

Re: Error connecting mysql database...
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

Reply
vikas1111's Avatar
vikas1111
Member
105 Posts
May 13th, 2008
06:15 AM
#6

Re: Error connecting mysql database...
Quote:
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 ???

Reply
rpnew's Avatar
rpnew
Familiar Sight
174 Posts
May 13th, 2008
07:02 AM
#7

Re: Error connecting mysql database...
Quote:
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

Reply
vikas1111's Avatar
vikas1111
Member
105 Posts
May 13th, 2008
07:15 AM
#8

Re: Error connecting mysql database...
Quote:
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 ?

Reply
Atli's Avatar
Atli
Moderator
1,866 Posts
May 13th, 2008
07:34 AM
#9

Re: Error connecting mysql database...
Quote:
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.

Reply
vikas1111's Avatar
vikas1111
Member
105 Posts
May 13th, 2008
07:42 AM
#10

Re: Error connecting mysql database...
Quote:
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%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN..
Is already there in the Variable Value field.. Is it correct ???

Reply
rpnew's Avatar
rpnew
Familiar Sight
174 Posts
May 13th, 2008
09:28 AM
#11

Re: Error connecting mysql database...
Quote:
Originally Posted by vikas1111
Thanks..
This.. %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem;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

Reply
vikas1111's Avatar
vikas1111
Member
105 Posts
May 13th, 2008
10:37 AM
#12

Re: Error connecting mysql database...
Quote:
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...

Reply
Atli's Avatar
Atli
Moderator
1,866 Posts
May 14th, 2008
01:20 AM
#13

Re: Error connecting mysql database...
Quote:
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: ( text )
  1. 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.

Reply
Reply
Not the answer you were looking for? Post your question . . .
170,098 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top PHP Forum Contributors