homepage Welcome to WebmasterWorld Guest from 54.205.144.54
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Fatal Error: undefined function mysql_connect()
mikejson




msg:1257651
 10:53 pm on Sep 28, 2004 (gmt 0)

Hey everyone, I'm surfing the net looking for answers but I thoguht I should post the question somewhere so I have something to fall back on.

I am running:

Windows Xp SP2
apache2
php5
mysql4.x

The are all running fine from what I can tell.

I have 1 problem, I cannot connect to the mysql server using php, it's giving me the error noted in the subject line. The error says the function is undefined but I assume it is in the .dll file that the php.ini file loads(php5apache2.dll for php to work on apache and php_mysql.dll loaded as an extension for php to talk to mysql). Everything loads fine, I don't get any errors when starting up apache, the phpinfo() page works perfectly, but it juts won't talk to mysql server...

Any thoughts?

 

Timotheos




msg:1257652
 11:03 pm on Sep 28, 2004 (gmt 0)

[php.net...]

In PHP 5, MySQL is no longer enabled by default, nor is the MySQL library bundled with PHP. Read this FAQ for details on why. Because of this, Windows users will need to enable php_mysql.dll inside of php.ini and either copy libmysql.dll into the Windows system directory or make it available to the PATH. For compiling, simply use --with-mysql=[DIR] where [DIR] points to your MySQL installation directory.

mikejson




msg:1257653
 1:24 am on Sep 29, 2004 (gmt 0)

I've done everything but

"For compiling, simply use --with-mysql=[DIR] where [DIR] points to your MySQL installation directory."

I don't know what this means :(

mincklerstraat




msg:1257654
 7:19 am on Sep 29, 2004 (gmt 0)

it means the directory in which mysql is located.

coopster




msg:1257655
 12:35 pm on Sep 29, 2004 (gmt 0)

You are running Windows so you more than likely did not compile PHP but are running PHP from a binary installation. Did you uncomment the MySQL extension yet in your
php.ini file?

See step 6 in message #2 in Installing PHP5 Unders Windows XP and Apache [webmasterworld.com].

mikejson




msg:1257656
 1:09 pm on Sep 29, 2004 (gmt 0)

mincklerstraat:

I know what the [DIR] means, I am saying I don't know how to compile PHP on a windows machine.

coopster:

I have uncommented all the extensions I wish to use, and I am not getting any errors that apache/php can't find anything(meaning I have the .dlls in the correct spot). It just doesn't know what the mysql functions are....

Any help would be appreciated. The php installation works fine otherwise, I've used basic php functions for, time, date, info... etc. They all work great, it just doesn't know where the functions for mysql are.

*edited for spelling/grammer*

jatar_k




msg:1257657
 5:38 pm on Sep 29, 2004 (gmt 0)

mikejson,

let's take a step back and have a look at what's going on here.

>> I am not getting any errors that apache/php can't find anything

actually that's not true, you are getting an error that there is an undefined function, which means php can't find something.

>> I've used basic php functions

so we know that php is where it needs to be

>> I have the .dlls in the correct spot

so we know, and hopefully have checked a bunch of times ;), that the dll's are in the right spot.

So, the way I see it everything seems to be in the right spot except there seems to still be confusion. So how could everything be in the right spot yet php can't find it? First think how does php/apache find things?

php.ini

>> I have uncommented all the extensions I wish to use

ok, but, something is still wrong

do you have only a single php.ini? (I have heard this problem many, many times on windows installs)
are you positive you are editing the one apache is using?

delete or rename the one you are editing and see if it still runs as is

mikejson




msg:1257658
 8:16 pm on Sep 29, 2004 (gmt 0)

I did a complete search of my machine to find all occurences of php.ini files. I found 1 php.ini, and the php.ini_old file that I created when I was trying to debug this problem, also found the php.ini-default files or whatever the php distribution ships with.

I'm going to go back to the very beginning and clean everything up, and configure it all again using the walk through.... who cares if I figure out what's wrong, I just want the damn thing to work :P

I'll report back asap.

mikejson




msg:1257659
 8:20 pm on Sep 29, 2004 (gmt 0)

and yes, I should correct myself. PHP and Apache aren't reporting any errors in finding the actually .dll files, I didn't mean it can't find functions(which I am assuming are in one of those .dll files it DOES find....)

My mistake.

mikejson




msg:1257660
 9:48 pm on Sep 29, 2004 (gmt 0)

I don't know what's going on.

it's giving me the same freaking crap....

anyone know where the mysql_connect() function is defined in php? is it in one of those dlls and maybe it just doesn't have it in there? I'm lost.

mikejson




msg:1257661
 1:00 pm on Sep 30, 2004 (gmt 0)

I've moved the php.ini file to the Apache2 root dir(default apache2 install) and the phpinfo() still says it's in C:\Windows, yet I've got show hidden and system files there, and it's not there. I also went into th command prompt and looked for it there(just in case it wasn't showing up in the Windows GUI) and it isn't there.

Why would phpinfo() be saying it's using the php.ini file in C:\Windows when there isn't one there? Is it because that is where I first put the file?

Note** I have restarted apache and the computer multiple times

coopster




msg:1257662
 1:49 pm on Sep 30, 2004 (gmt 0)

I have a setup almost exactly like yours, the main difference being I DO NOT have XP Service Pack 2 installed, and I just...
  1. Ran phpinfo().
  2. The Configuration File (php.ini) Path states C:\WINDOWS\php.ini
  3. Stopped Apache.
  4. Moved my php.ini from C:\WINDOWS\ to C:\Program Files\Apache Group\Apache2\
  5. Started Apache
  6. Ran phpinfo() again.
  7. Configuration File (php.ini) Path states C:\Program Files\Apache Group\Apache2\

Therefore, I would venture to guess that if phpinfo() is telling you it found the php.ini file in a certain path, then it found it in that path. If you are using MS Internet Explorer for the browser, clear the cache and try again. If phpinfo() tells you that it found the file there, I'm guessing it found the file there. Try what jatar_k mentioned earlier, try renaming the only php.ini file you have to something like php.bak and stop and restart apache, and call phpinfo() again. If it works, then it is indeed finding the php.ini file somewhere else and you'll have to track it down.

mikejson




msg:1257663
 2:08 pm on Sep 30, 2004 (gmt 0)

AHHA!

It runs without the php.ini file.... now how can I tell where it is?

I've went through command to look for it, it's not viewable through windows explorer...

coopster




msg:1257664
 2:23 pm on Sep 30, 2004 (gmt 0)

OK, I just renamed my
php.ini as well and stopped and restarted Apache. There is absolutely no php.ini file on my system anywhere. Apache will start without error, and phpinfo() WILL indeed run, but searching down through the directives, I find absolutely zero reference to MYSQL, therefore the extension is not loading. The Configuration File (php.ini) Path still shows C:\WINDOWS though and I don't know why -- I would have to research this, and maybe it's a bug or perhaps it's an internal thing. Either way, it is a bit deceptive.

<edit>
OK, time out. I just realized that it says
C:\WINDOWS, not C:\WINDOWS\php.ini! Yes, the C:\WINDOWS directory is the last path being searched and it didn't find any php.ini file there, so this is a correct identification.
</edit>

Either way, all I have to do is copy my php.ini file with my extensions uncommented back into the C:\WINDOWS directory, stop apache, start apache, and I'm back on track.

[edited by: coopster at 2:47 pm (utc) on Sep. 30, 2004]

coopster




msg:1257665
 2:31 pm on Sep 30, 2004 (gmt 0)

The best I can find regarding the how/why of
php.ini during startup is on the Configuration [php.net] page and the FAQ [php.net] link from there.

One other thing that is coming to mind as I read those pages though is that you should also make sure you don't have a php-SAPI.ini file laying around somewhere.

mikejson




msg:1257666
 2:44 pm on Sep 30, 2004 (gmt 0)

tell me this:

put your php.ini file in your apache2 directory and restart apache, and tell me if that changes your config location to apache2 directory....(edit DOH, you already did this....)

on mine, it doesn't change the install directory, but the FAQ link you gave says it looks in apache2 directory first, then goes out to the windows directory....

Mine doesn't change(whether it actually looks in different spots I can't be certain.).

What should I try next?....

coopster




msg:1257667
 2:50 pm on Sep 30, 2004 (gmt 0)

Did you also make sure you don't have a
php-SAPI.ini file laying around somewhere?
mikejson




msg:1257668
 2:53 pm on Sep 30, 2004 (gmt 0)

BING, something a friend found for me....

phpfreaks [phpfreaks.com]

it doesn't help the situation much, but at least I'm not alone.

It really only says that the person having the problem went the cgi instead of the module way.

maybe I should try that :( I really think the module way is what I want.

[edited by: coopster at 4:13 pm (utc) on Sep. 30, 2004]
[edit reason] fixed sidescroll [/edit]

coopster




msg:1257669
 3:51 pm on Sep 30, 2004 (gmt 0)

>>went the cgi instead of the module way

What do you have in Apache ( httpd.conf ) for your PHP configuration settings?

By the way, I found what I was looking for earlier...


PHP searches for php.ini in the following locations (in order):
  • PHPIniDir directive (Apache 2 module only)
  • HKEY_LOCAL_MACHINE\SOFTWARE\PHP\IniFilePath
  • The PHPRC environment variable
  • Directory of PHP (for CLI), or the web server's directory (for SAPI modules)
  • Windows directory (C:\windows or C:\winnt)

Resource:
[php.net...]

mikejson




msg:1257670
 4:05 pm on Sep 30, 2004 (gmt 0)

YES!

What I did....

In one of the tutorials that I read it told me to edit the PHPIniDir = "C:\PHP"

I've changed this back to "./" and it's now reading the apache directory for php.ini and loading the settings in there

*cheer* *cheer*

Thanks for getting me on the right track.

I'm getting more errors now, but they are different, it's "seeing" the mysql functions now, now I have to configure mysql properly :)

coopster




msg:1257671
 4:37 pm on Sep 30, 2004 (gmt 0)

>>In one of the tutorials that I read it told me to edit the PHPIniDir = "C:\PHP"

The example in the PHP Apache 2.0.x on Microsoft Windows [php.net] installation instructions is probably where you came across that directive and it's example setting. But you didn't change it to reflect the correct path to your php.ini file ;)

Glad you got it.

mikejson




msg:1257672
 1:52 pm on Oct 1, 2004 (gmt 0)

yes, very silly mistake... the real problem though, is phpinfo() telling me it's reading the php.ini file from the C:\windows directory when infact,it was reading from the C:\php directory, not finding anything and initializing defaults....

I personally, would like to see php bomb out and say "Hey stupid, there is no php.ini file for me to read, where you said it was!"

would make troubleshooting this sort of problem alot easier :P

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved