siterightpoint — 2013-07-05T12:47:04-04:00 — #1
I've tried various versions of this string but here's how i'm trying to connect to my DB as follows:[/B]
$link = mysql_connect("$hostname", "$username", "$password")or die("Could not connect");
mysql_select_db("$database") or die("Could not select database");
I'm getting this error via my localhost:
Fatal error: Call to undefined function mysql_connect() in C:\Webserver\Apache Software Foundation\Apache2.2\htdocs\SearchEngine.php on line 43
Thanks in advance.
fretburner — 2013-07-05T12:55:31-04:00 — #2
Try checking your php.ini file and make sure this line isn't commented out:
It's worth mentioning that the PHP mysql extension has been depreciated and will be removed from PHP at some point, so you should really be using the mysqli (or, better still, PDO) extension - just enable
extension=php_mysqli.dll in your php.ini file and you should be good to go
Edit: Note that you'll need to restart Apache after you make changes to php.ini
siterightpoint — 2013-07-05T13:36:14-04:00 — #3
Thanks Fret. I should have mentioned I already checked the extension=php_mysqli.dll and there is no ";" in place in front of it because I removed it during the install. Any other ideas?
fretburner — 2013-07-05T13:42:04-04:00 — #4
You could try creating a new PHP file like this:
<?php phpinfo(); ?>
When you browse to the file, you'll get a screen that details all of PHP's settings, and what modules are enabled etc.
Check to see if there's an entry for mysql or mysqli.
Did you install Apache/PHP/MySQL individually, or you're using some kind of LAMP package like WAMP or XAMPP?
siterightpoint — 2013-07-05T13:47:09-04:00 — #5
I installed them individually. mysqli and mysqli are not commented out, per the php.ini file. I made mysqli active just now to be sure. Also thanks for the tip on deprecation.
siterightpoint — 2013-07-05T13:51:11-04:00 — #6
hey, you're right. I created the file and I don't see anything about MySQL or mysqli. What should it say and how do I activate them?
fretburner — 2013-07-05T13:57:58-04:00 — #7
Near the beginning of the phpinfo output, check a setting called 'Loaded Configuration File' and make sure it corresponds to the php.ini file you've been editing. I've had situations where there were ini files in a couple of locations and I wasn't sure if I was editing the right one.
siterightpoint — 2013-07-05T14:00:29-04:00 — #8
fretburner — 2013-07-05T14:03:11-04:00 — #9
Hmmm.. do get any errors in your Apache or PHP error logs?
siterightpoint — 2013-07-05T14:12:10-04:00 — #10
My Apache error log was easy to find and nope I didn't see any files error files created there. How do I check for PHP?
fretburner — 2013-07-05T14:14:35-04:00 — #11
Under the 'Core' section of the phpinfo output, there's a setting 'error_log' which shows which folder the log is in.
siterightpoint — 2013-07-05T14:19:21-04:00 — #12
Core says "no value" under both local and master value. Also display_errors says "on" if that means anything to you. Thanks again for continuing to work with me. Believe it or not i'm been looking for solutions for a while..
fretburner — 2013-07-05T14:36:45-04:00 — #13
One thing I've seen suggested over on the PHP manual is to try copying php_mysqli.dll (from the php/ext folder) and libmysql.dll (from your mysql/bin folder, I think) to your windows/system32 folder, and restart apache again.
siterightpoint — 2013-07-05T15:03:32-04:00 — #14
The libmysql.dll folder was actually in the Webserver folder but that's ok, I found it. I moved both files you suggested to the System32 folder and restated Apache. I tried several variations of the connect string again and no luck.
siterightpoint — 2013-07-05T15:08:17-04:00 — #15
Do you think there's a problem with my syntax perhaps?? I've tried multiple variations..
fretburner — 2013-07-05T15:11:01-04:00 — #16
No, if it was just that then you'd be getting a different error. For some reason it seems that PHP isn't loading the extensions.
I'm afraid I don't know what else to try at this point. The only thing I could suggest is downloading a complete LAMP package for Windows - I've used WAMP and XAMMP in the past and never had any trouble with either. They should be able co-exist with your existing setup as long as you only have one set of Apache and MySQL servers running at a time (or you change the default ports).
siterightpoint — 2013-07-05T15:43:45-04:00 — #17
thank you very much for helping me thus far. I'll keep trying for a while and if I can't figure it out i'll do what you suggested and install a WAMP. If I find a solution before then i'll post on this thread. Cheers.