Simple connection between MySql DB and Localhost

[B]Hey all,

I’ve tried various versions of this string but here’s how i’m trying to connect to my DB as follows:[/B]

// connect
$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.

Hi,

Try checking your php.ini file and make sure this line isn’t commented out:

extension=php_mysql.dll

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 [fphp]mysqli[/fphp] (or, better still, [fphp]PDO[/fphp]) 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

fretburner,

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?

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?

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.

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?

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.

Yup. Its pointing to it.

Hmmm… do get any errors in your Apache or PHP error logs?

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?

Under the ‘Core’ section of the phpinfo output, there’s a setting ‘error_log’ which shows which folder the log is in.

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…

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.

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.

Do you think there’s a problem with my syntax perhaps?? I’ve tried multiple variations…

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).

fretburner,

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.