31

I just changed my server and experience these errors below:

Fatal error: Call to undefined function mysqli_init() in /home/blacktwitter/public_html/system/database/drivers/mysqli/mysqli_driver.php on line 126
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/blacktwitter/public_html/system/database/drivers/mysqli/mysqli_driver.php:126)

Filename: core/Common.php

Line Number: 564

Backtrace:

A PHP Error was encountered

Severity: Error

Message: Call to undefined function mysqli_init()

Filename: mysqli/mysqli_driver.php

Line Number: 126

Backtrace:

Website is in Codeigniter. It works on one server very well and on the local machine too. But when I upload that website at the new server I have that errors. Of course I changed important parameters like database connection, base_url() etc.

I was suspicious about database, but I have created a new database and user etc. and changed connection info.

Why does this happen? It will be helpful to know if it is a bug at the server or at the website. Also when I create some index.html with some test code everything is fine.

4
  • 3
    Check the phpinfo() for the new server and make sure mysqli is installed.
    – DFriend
    Commented Nov 9, 2015 at 17:20
  • did you solve the it?
    – hybrid
    Commented Jan 29, 2016 at 18:13
  • @hybrid i dont know why you open bounty for this. This comes cz of user mistake. As well if there is an bug we cant check it. Cz no codes are here Commented Feb 2, 2016 at 11:42
  • I would suggest you to reinstall mysql and add make needed changes in php.ini Coz maybe some files are missing/not properly added in the installed mysql application.
    – Varshaan
    Commented Feb 3, 2016 at 12:43

14 Answers 14

39
+25

It is not a bug in your application, it is just a missing driver, so, you have couple of options...

Go to your php init and uncomment the following:

extension=php_mysqli.dll

If not, try installing it at your server, it varies depending on your distribution.

Try installing php5-mysqlnd

If you cannot do it by hosting restrictions then just move to mysql driver (wont need to change other configurations or queries in CodeIgniter or anything else...)

like this (at your config file)

$db['default']['dbdriver'] = 'mysql'; (you might have mysqli now)
2
  • with php 5.4 or above mysqlnd seems to be a default option ? mysqlnd php-mysqlnd Commented Oct 9, 2018 at 15:01
  • Nice, this was the solution for me. In my case I'm running centos 7 and I had to restart the httpd service to get it working. "sudo yum systemctl restart httpd"
    – Herii
    Commented May 7, 2021 at 6:19
28

I just had this issue on a ubuntu16.04, php7.1 install with Codeigniter 3.

Solution was simple (if hard to find!)

sudo apt-get install php7.0-mysql

I realised that the mysql*.ini files where missing from the etc/php/7.1/mods-available directory. Not sure how it happened, but that worked for me.

If you use 7.2, simply type sudo apt-get install php7.2-mysql

2
  • mmm... The question was asked on november 9, 2015 and PHP 7 was released on december 17, 2015. I'm sure there was another solution at this time. Commented May 29, 2017 at 21:43
  • I think it's not important, I was looking for this solution, and the versions are obviously updated from time to time. Commented Aug 2, 2017 at 13:41
15

Use this:

sudo apt-get install php7.*-mysqli

or

sudo phpenmod mysqli
sudo service apache2 restart
7

This is actually not a CodeIgniter issue but PHP installation issue.

I have installed PHP5.6 in my Linux server and is having a hard time following the googled solutions of using the ff command in order to install the missing mysqli_extension in PHP.

What I tried is but is returning the warning message: Unable to locate package php5-mysqli

sudo apt-get install php5-mysqli

However, my php version is 5.6 so I tried

sudo apt-get install php5.6-mysqli

Then it works.

0
4

The problem is php's mysql extension might not have installed, if you are using php 7, just issue the below command and install the extension,

sudo apt-get install php-mysql
1
  • 1
    After doing it you must restart mysql server. - sudo service apache2 restart
    – donkey
    Commented May 18, 2022 at 13:34
2

Open the folder where you have installed PHP, Edit php.ini file
uncomment this line: extension=php_mysqli.dll

0
1

In Linux, you can install MySQL driver extension.

sudo apt-get install php-mysql

In Windows with XAMPP, the driver has already saved in ext directory, but you need to enable it in php.ini. You need to uncomment this line:

extension=php_mysqli.dll

You also need to check the extension directory location in php.ini. I use absolute path (not relative path) declaration to make it works.

extension_dir="your\absolute\path\to\xampp\php\ext"

For example,

extension_dir="C:\xampp\php\ext"
1

I know the difference is not that big but for the ones who are running CentOS:

sudo yum install php-mysqli
sudo systemctl status httpd

We are installing the mysqli extension using yum and then restarting our httpd server for the changes to take effect, and in case you are not using httpd just replace httpd for the name of your service.

0

For me this was a missing line in php.ini that solved it, as I copied another php.ini file to my XAMPP installation. Worth checking if the line: "extension=php_mysqli.dll" exist (if running Windows, but this isn't applicable for OP, as it's a Linux system), or if the "extension_dir" exists and is correct.

1
  • I am using web server (cPanel) and mysqli is installed. I tried removing it and adding it also. Still the problem exists.
    – hybrid
    Commented Feb 3, 2016 at 5:10
0

1、apt-get install (yum, compile install whatever) php5-mysqlnd extension.

2、if not work, make sure mysqli is loaded

    root@x19-ws07-1:/etc/php5/apache2# cat /proc/31682/maps | grep mysql

if is loaded, you can see:

    7f2cd3266000-7f2cd3285000 r-xp 00000000 fd:00 864561                     /usr/lib/php5/20131226/mysqli.so
    7f2cd69ef000-7f2cd6a2e000 r-xp 00000000 fd:00 864559                     /usr/lib/php5/20131226/mysqlnd.so

3、if not loaded use php --ini to find config file

    xxxx@xxxx:~$ php --ini
    Configuration File (php.ini) Path: /etc/php5/apache2
    Loaded Configuration File:         /etc/php5/apache2/php.ini
    Scan for additional .ini files in: /etc/php5/apache2/conf.d
    Additional .ini files parsed:      /etc/php5/apache2/conf.d/05-opcache.ini,
    /etc/php5/apache2/conf.d/20-mysqli.ini

4、if not config extension, config like this and remember restart your web server

    xxxx@xxxxx:~$ cat /etc/php5/apache2/conf.d/20-mysqli.ini
    ; configuration for php MySQL module
    ; priority=20
    extension=mysqli.so
0

I tried, comment out below line in /etc/php/cli/php.ini file.

extension=php_mysqli.dll

I am using Ubuntu 16.04 on AWS-EC2 instances and PHP 7.0. This solved my problem.

0

In my case using Windows I had all the necessary extensions uncommented, but it wasn't loading them. Then, I checked the extension directory variable in php.ini and it was as "ext", but then I remembered I'd had a similar problem previously. So what I did was basically put the explicit directory. Something like this:

extension_dir = "C:\php\ext"

Of course the specific ext directory depends entirely on your own setup and locations.

After updating the php.ini file you just have to restart Apache to apply the changes.

If you installed your Apache manually (not using pre-packaged solutions like XAMPP or WAMPP) you just have to use these commands in either a Command Prompt or a Powershell with administrator rights.

net stop Apache2.4

net start Apache2.4

-1

If your webserver is running with a lower version of MySQL, then you will get this error as MySQLi is not supported in MySQL < 4.1.3

It is highly recommended to go with MySQLi instead of going back to MySQL extension.

More info on php.net

1
  • I checked the version.It is the latest one
    – hybrid
    Commented Feb 8, 2016 at 17:39
-1

I suggest you do the following:

change:

'dbdriver' => 'mysqli',
'dbprefix' => '',

to:

'dbdriver' => 'mysql',
'dbprefix' => '',

in database.php file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.