1

I just downloaded a fresh copy of CI from their site(version 3.0.3) and simply configured database and loaded it, but i am having error.

Below is my database configuration in config.php

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'shortagesdb',
'dbdriver' => 'mysql',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,//(ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

);

and here is what i am doing in my controller i-e simply loading database

public function index()
{
    $this->load->database();
    $this->load->view('welcome_message');
}

Nothing fancy here and i am getting this exception no matter what

PHP Fatal error:  Call to undefined function mysql_connect() in D:\Projects\ims\system\database\drivers\mysql\mysql_driver.php on line 136

Any help would be highly appreciated

7
  • 1
    change 'dbdriver' => 'mysql' to 'dbdriver' => 'mysqli' Commented Nov 22, 2015 at 7:44
  • but i am using mysql or mssql, why should i use mysqli ? Commented Nov 22, 2015 at 7:50
  • mysqli means mysql inproved. So, nothing to worry. Commented Nov 22, 2015 at 7:52
  • ahh got, you, let me try Commented Nov 22, 2015 at 7:56
  • @ChetanAmeta did what you asked and got this error again PHP Fatal error: Call to undefined function mysqli_init() in D:\Projects\ims\system\database\drivers\mysqli\mysqli_driver.php on line 125 Commented Nov 22, 2015 at 8:01

2 Answers 2

3

Codeigniter 3 won't support MySQL. MySQL is deprecated in version 3.0

Try this

$db['default'] = array(
'dsn'   => '',
'hostname' => 'localhost',
'username' => 'root', # check username
'password' => '', # check password
'database' => 'shortagesdb', # check DB name is correct
'dbdriver' => 'mysqli', # remove mysql
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'), # remove TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

the usename and password is correct. What if i want to use mssql server ? i get the same error
you cant use mysql in CI 3.
what do i need to do, if i want to use mssql server ?
no you cant. Or use CI 2. MySQLi is improved security of MySQL
i have done what you suggested above, now having this error PHP Fatal error: Call to undefined function mysqli_init() in D:\Projects\ims\system\database\drivers\mysqli\mysqli_driver.php on line 125
|
1

The problem might be in your php.ini file, go to you php folder and open that file in a text editor. Now find the extensions and uncomment this:

extension=php_mysqli.dll

Also check that you extension path is correctly directed to your ext folder in the php root location.

1 Comment

if are you using php7 make sure you using the php.ini of php 7. /etc/php/7.0/cli

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.