Error: Call to undefined function mysql_connect()

Posted on 2015-01-13
Last Modified: 2015-02-05
I had apache, php, MySQL installed on my PC when the OS was Windows XP.

At the time, I used wamp to install them.

Recently, my PC was changed out for new PC with Windows 7, 64bit machine.

For the past 2 days how, I have had little success trying to reinstall apache, php and MySQL.

Initially, I tried using WAMP but after several unsuccessful attempt to fix missing dll issue, I tried using xamp.

That too was giving me same error.

So, I decided to do it manually.

First, I successfully installed apache.

Then I successfully installed php (tested with phpinfo to confirm).

Finally, I successfully installed MySQL.

I was able to recreate the database and tables I had before switching off PC.

The issue now is running my php app that used to work.

I just keep getting the error:

Call to undefined function mysql_connect() ...

I am also asking to be held by hand to point out what I am doing wrong.

I have been looking at the entries with phpinfo but I can't see what stands out.

Any assistance is greatly appreciated.
Question by:sammySeltzer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +1
LVL 10

Expert Comment

ID: 40547186
I believe the MySQL extension has been depreciated and replaced with mysqli.  A new version of PHP may therefore not support the old extension.

Try changing mysql_connect() to mysqli_connect() and see if that stop the error on that line.  If it does you either need to revert back to an older PHP version, or update all calls to the old extension.
LVL 28

Author Comment

ID: 40547236
Thanks for that information.

I didn't know that. I am a .net developer for the most part.

In any case, after making that change, still got same error except that now, it says Call to undefined function mysqli_connect(...)
LVL 53

Expert Comment

ID: 40547237
the fact that both wamp and xamp had issues and you are also having issues with a manually instaled version suggest that the problem is related to the change of operating systems and setting appropriate for XP are not valid for 7. you might want to look at the .ini files for wamp which documents what a lot of the settings need to be.  Also look at where you have things located and how you have virtual hosts defined.

There might also be an issue if you are running a mix of 64-bit and 32-bit.

Basically the error indicates the PHP is not interfacing with mysql if you get the error with mysql-_connect(), then that is definitely the case.

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

LVL 28

Author Comment

ID: 40547254
Ok, back to wamp and xamp, I couldnot even complete the installation.

The specific error I was getting with wamp or xamp is that I was missing misvcr100.dll.

I don't believe the issues are related.
LVL 53

Expert Comment

ID: 40547283
I think you mean msvcr100.dll which is part if the Visual C crud that Microsoft pushes out to do internal interfacing:

You can get a free download at:

I had the same problem when a upgraded to the lastest wamp version to support PHP 5

LVL 28

Author Comment

ID: 40547326
Sorry about the misspelling but I actually meant this:

Notice 110, 100.

When I downloaded dll from the same link you provided, I started getting a different error.

When I researched that error, the error suggests that the dll was either corrupt or conflicted with OS bit (64 or 32).

It didn't matter what solution I tried, it didn't work for me.

Anyway, as stated, right now, I have done the installations manually.

I just think there is some misconfiguration somewhere.

If I don't get any useful help today or can't google any helpful info, I will have to uninstall everything and start all over again.

Expert Comment

ID: 40548406
The error probably indicates that the required MySQLi extension is not loaded.
You should check the php logfile, it should be located under your php installation\logs directory.
Check your php.ini file (you can use phpinfo() to find the inifile being used) and make sure the path to your extensions is correct (Ie. extension_dir = "C:\php\ext").
Also verify the presence of a line "extension=php_mysqli.dll" in that same php.ini file.
Check if the required extension exists (php_mysqli.dll).

When all these settings are correct and the file php_mysqli.dll exists, you can verify that is loaded by checking the phpinfo() page, there should be a configuration header named mysqli.
LVL 28

Author Comment

ID: 40548854
Hi, Antyrael,

Maybe, we are getting somewhere here.

I don't see a configuration header that says mysqli.

I  see mysqlnd

Also, extension_dir points to C:\php, not C:\php\ext even though my ini file has the extension pointing to C:\php\ext

Expert Comment

ID: 40548891
Hi SammySeltzer,

Did you make any changes to your php.ini file? If so, you will need to restart Apache in order for these changes to be processed.
Is the setting "extension_dir" in your php.ini file commented out perhaps? Or is there another "extension_dir" defined in the inifile?
LVL 28

Author Comment

ID: 40548907
I did restart Apache but phpinfo still says c:\php

Here are the files:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"
; On windows:
 extension_dir = "c:\php\ext"

Initially, I commented out this line:
extension_dir = "./"

but then I uncommented it in my confusion.

Should it remain commented out?

Expert Comment

ID: 40550659
You should only have one active line, so yes, you should comment it out again, then restart Apache.
Is the line with "extension=php_mysqli.dll" also uncommented?
If yes, is there a file php_mysqli.dll in your ext folder?

If it's not set already, you should uncomment the "error_log" setting and provide a path for a logfile (ie. C:\php\Logs\error.log), if php is unable to load the mysqli extension the logfile will tell you.
LVL 28

Accepted Solution

sammySeltzer earned 0 total points
ID: 40551744
Well, I said yesterday that if I didn't get  a usable answer, I would uninstall everything and start all over.

I did that last night, tried the wamp install again and for some reason, this time, it worked, YEA!

So, I am deleting with a different issue. So, I will close this now.

Expert Comment

ID: 40552109
Sorry, I was unavailable last night, couldn't be helped.
Well, at least you got it working, so that's good.
LVL 28

Author Closing Comment

ID: 40590667
Please delete as I was unable to get a resolution to the problem.

I had to uninstall the app from my system and tried a new approach that worked for me.

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySQL limit and not so limited 13 41
How to use session variables in php? 22 52
How do I update select listbox after search 2 26
PHP substring 3 15
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question