PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 10, 2022

[FIXED] Unable to connect to database in codeigniter in MAMP

 January 10, 2022     codeigniter, mamp, php     No comments   

Issue

Hi I am using MAMP and Codeigniter. The Codeigniter version is 2.x I built an application on Linux [LAMP] now I want to move the application to MAC Book. When I Open the Localhost it shows me error of :

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core/Loader.php

Line Number: 347

Now what could be the reason? My Credentials are correct but maybe I am trying to access it in wrong manner?

  $active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'biz_prov';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

In LAMP I had to do localhost/project but here I Have localhost:8888/projectname can this be the possible reason?


Solution

There could be couple of reasons for this issue:

  • dbdriver: Replacing mysql with mysqli worked for me, if doesn't work, you can also try with sqlsrv

    $db['default']['dbdriver'] = 'mysqli';  // mysqli for mac, 
    
    $db['default']['dbdriver'] = 'mysql';   //mysql for windows
    
  • pconnect: You may need to set to FALSE

    $db['default']['pconnect'] = TRUE;
    
  • And,Credentials. Do verify your username and password, cuz it gives the same error when credentials doesn't match.

One thing at a time, You may not need to modify all, but it won't hurt to try when something doesn't work :)

Sample for reference:

$db['default']['hostname'] = 'localhost'; // try using ip or ip and port if needed(trying doesn't hurt).
$db['default']['username'] = '*****'; // provide your username
$db['default']['password'] = '*****'; // provide your password
$db['default']['database'] = 'storedb';
$db['default']['dbdriver'] = 'mysqli';  // mysqli for mac, mysql for windows
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


Answered By - f-society
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing