Call to undefined function mysqli_connect on PHP for windows
I have the following code:
If I run this I will get this error message:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect()
From what I have read, you’re supposed to uncomment parts in your php.ini file. There is no php.ini in my PHP folder, but only php.ini-development and php.ini-production.
I’ve tried renaming one of the files to php.ini and uncommenting extension=mysqli , but the problem is still there.
How can I solve this issue?
3 Answers 3
I was having this same issue, and most stackoverflow answers didn’t really clearly address this other step you need to take in setting up your php.ini. If you just uncomment extension=mysqli php still has no idea where any of your extensions are actually located, so it will fail to load them. Locate the section of your php.ini that looks something like:
And then uncomment the bottom «extension_dir» value and fill in the value with the absolute path of your «ext» directory, ie:
Once I completed these two steps (uncommenting extension=mysqli and then adding the absolute path in extension_dir), mysqli loaded correctly
As the setup say you have to rename one of those 2 you have, if you don’t PHP will go with defaults.
So change one of them to php.ini and uncomment the line — this should not really be needed as far as i recall.
For Windows, you can find the file in the C:\xampp\php\php.ini-Folder (Windows) or in the etc-Folder (within the xampp-Folder).
Under Linux, most distributions put lampp under /opt/lampp , so the file can be found under /opt/lampp/etc/php.ini .
If you can’t find it. Then you should rename one of those to php.ini file.
Not the answer you’re looking for? Browse other questions tagged php mysql or ask your own question.
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2020.10.13.37803
Call to undefined function mysql_connect
I just installed PHP and Apache on my home PC. When I try to call function mysql_connect I get:
I have loaded php.ini where I have uncommented lines extension=php_mysql.dll and extension=php_mysqli.dll and changed extension directory to extension_dir = «C:\php\ext» — which is the directory where files php_mysql.dll and php_mysqli.dll are. How can I fix this problem?
13 Answers 13
After looking at your phpinfo() output, it appears the mysql extensions are not being loaded. I suspect you might be editing the wrong php.ini file (there might be multiple copies). Make sure you are editing the php file at C:\php\php.ini (also check to make sure there is no second copy in C:\Windows).
Also, you should check your Apache logs for errors (should be in the \logs\ directory in your Apache install.
If you haven’t read the below, I would take a look at the comments section, because it seems like a lot of people experience quirks with setting this up. A few commenters offer solutions they used to get it working.
Another common solution seems to be to copy libmysql.dll and php_mysql.dll from c:\PHP to C:\Windows\System32.
Background about my (similar) problem:
I was asked to fix a PHP project, which made use of short tags. My WAMP server’s PHP.ini had short_open_tag = off . In order to run the project for the first time, I modified this setting to short_open_tag = off .
PROBLEM Surfaced: Immediately after this change, all my mysql_connect() calls failed. It threw an error
fatal error: call to undefined function mysql_connect.
Solution: Simply set short_open_tag = off .
My PC is running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file «httpd.conf» (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was sensitive to slashes. You can check if «php.ini» is read from the right directory. Just type in your browser «localhost/index.php». The code of index.php is the following:
There is the row (not far from the top) called «Loaded Configuration File». So, if there is nothing added, then the problem could be that your «php.ini» is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). So, in order to make it work I did the following step. I needed to change from
Pay the attention that the last slash disturbed everything!
Fatal error: Call to undefined function mysql_connect()
I have set up PHP, MySQL, and Apache. localhost() for PHP and it is working well. But after I downloaded MySQL, it reports:
Fatal error: Call to undefined function mysql_connect()
How can I fix this?
17 Answers 17
You upgraded to PHP 7, and now mysql_connect is deprecated. Check yours with:
Change it to mysqli_connect as in:
If you’re upgrading legacy PHP, now you’re faced with the task of upgrading all your mysql_* functions with mysqli_* functions.
If you get this error after upgrading to PHP 7.0, then you are using deprecated libraries.
mysql_connect — Open a connection to a MySQL Server
Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
Open your terminal and run bellow command.
If you are running PHP you will also need to install the php module for mysql 5:
Verify that your installation of PHP has been compiled with mysql support. Create a test web page containing and load it in your browser. Search the page for MySQL. If you don’t see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in
Check if you forgot to enable the options below(loads the modules for mysql among others):
In PHP 7. You probably have PHP 7 in XAMPP. You now have two option: MySQLi and PDO.
This error is coming only for your PHP version v7.0. you can avoid these using PHP v5.0 else
i made only mysqli from mysql
I had this same problem on RHEL6. It turns out that the mysql.ini file in /etc/php.d only had a module name but needed a full path name. On my RHEL6 system the entry that works is:
After modifying the file, I restarted apache and everything worked.
A solution could be to use adapter functions like these to start using mysqli instead of mysql over your entire application:
Am using windows 8 n this issue got resolved by changing the environment variables
follow these steps: Open my computer properties->advanced system settings->Environment variables. Under ‘system variables’, select ‘path’ and click on ‘edit’ In ‘variable value’, add ‘C:\php;’ OR the path where php installed.
click OK and apply the settings and restart the system. It should work.
Here is a quick fix:
All the pros will probably hate me for this answer. But I got the same error on a server: Fatal error: Uncaught Error: Call to undefined function mysql_connect() that was using PHP 7. Did not have time to rewrite all the mysql code so a quick, temporary fix if anyone needs it is in CPANEL to look for PHP Configuration and change the version for that account to something like PHP 5.4 instead of PHP 7. Then the code worked fine without the above error.