0

I have gone through number of threads on stackoverflow and on other forums to find the answer but could not find relevant answer. People have applied different approaches but none has worked for me thus far.

I am using CI 3 on XAMPP and whenever I load database library in the model, I run into 500 Error.

Here is my CI database config info:

    'hostname' => 'localhost',
    'username' => 'my_user',
    'password' => 'my_pass',
    'database' => 'prod_db',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,

PHP ini db libraries are as below:

extension=php_bz2.dll
extension=php_curl.dll
extension=php_fileinfo.dll
;extension=php_ftp.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_intl.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
extension=php_mbstring.dll
extension=php_exif.dll      ; Must be after mbstring as it depends on it
extension=php_mysqli.dll
;extension=php_oci8_12c.dll  ; Use with Oracle Database 12c Instant Client
;extension=php_openssl.dll
;extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll

; The MIBS data available in the PHP distribution must be installed.
; See http://www.php.net/manual/en/snmp.installation.php
;extension=php_snmp.dll

My model code is as below:

class loginmodel extends CI_Model {


    public function validate_login($username, $password) {

        $this->load->database();
        $var = 0;
        return $var;

    }

}

Whenever I remove $this->load->database(); from the model, my code runs and i am able to redirect to a "Login Failed" page. BUT, whenever I load my database library in autoload.php or load it in above model, code fails.

Autoload.php $autoload['libraries'] = array('database');

Apache error logs showed below errors but I could not figure as why this was happening.

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_mysqli.dll' - The specified module could not be found.\r\n in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\php\\ext\\php_pdo_mysql.dll' - The specified module could not be found.\r\n in Unknown on line 0

Please advise.

EDIT:

I verified all config to be OK and as stated in the comments, I added environment variables to windows and verified through PHPInfo that mysqli and mysqlnd were loaded.

  • Possible duplicate of [How to fix PHP Warning: PHP Startup: Unable to load dynamic library 'ext\\php\_curl.dll'?](https://stackoverflow.com/questions/25027013/how-to-fix-php-warning-php-startup-unable-to-load-dynamic-library-ext-php-cu) – Yusril Herlian Syah Oct 14 '17 at 18:31
  • Did you try to restart Apache (along it's all services - including PHP) at least once? – Tpojka Oct 14 '17 at 18:59
  • I added the path in environment variables and restarted Apache. Mysql error went away but the actual issue remains. Whenever I load the database library in codeigniter, i get 500 error. but when i remove the library from autoload.php or the model, code runs fine. For reference though, I am on PHP 7.1.8 with Apache 2.4. And phpmyadmin runs just fine (prompting me to verify that there is no issue with mysqli being picked up by the system now. And when i echo phpinfo, I see that mysqli and mysqlnd are loaded. I will appreciate any feedback if this was resolved by someone earlier. – user3396788 Oct 14 '17 at 19:12
  • ugh, what a mistake! can't believe it. So this thread really helped. And regarding error, after making sure that config was OK, i checked the migrated database in xampp and my db username was not defined. Managed to verify it through running a fresh copy of CI in a different directory in the server and reproducing the error. While clean CI install did throw the error, I guess that my earlier code did not return any errors because .htaccess was configured that way to suppress them. thanks folks. – user3396788 Oct 14 '17 at 19:41

1 Answers1

0

Despite getting all the config right, error still persisted and I did a clean install of CI to reproduce library load failure. This time CI returned an error that db access was denied.

I then realized that after migration, database user was not created in the new environment. So once I created the desired user and assigned it required privileges, I was able to run the code just fine.

Therefore, if anyone encounters such issue in future, below steps might help:

  • First and foremost, verify if your desired user can access the database.
  • Modify your .htaccess to use your desired URL schemes only after verifying that database connection is working
  • Then verify that absolute path is available in PHP.ini on XAMPP.
  • Plus, verify that PHP is added in the environment variables. My Values on Windows 10 are as follows: Variable Name: PHP , Variable Value: C:\xampp\php\ext
  • In CI, mysqli is selected as database driver
  • In PHP.ini mysqli extension is enabled. i.e. php_mysqli.dll
  • Echo PHPInfo to verify that mysqli and mysqlnd are available in your installation.

If nothing works, do a clean install of CI on a separate directory and load database library after setting up your database configuration and before setting up .htaccess until you can reproduce the error.

Hope that error will be eliminated!