Welcome Guest, Not a member yet? Register   Sign In
Failing to connect to database
#1

(This post was last modified: 02-21-2018, 03:02 PM by ciadmin. Edit Reason: redacted password )

Just started using CodeIgniter today following the tutorial on the site and ran into a problem with setting up the database. Looked around various other forums and sites for a couple hours to no avail of how to fix the problem. My setup is a local MySQL database, CodeIgniter and  XAMPP.

The exact error message is:
Quote:Message: mysqli::real_connect(): (HY000/1045): Access denied for user 'unityAdmin'@localhost (using password: YES)

Filename: mysqli/mysqli_driver.php
Line Number: 201

Now I know the credentials themselves are working fine since I can manually connect to the database via command line or Sequel Pro with the credentials that are in the database.php config file which looks like:

PHP Code:
$db['default'] = array(
 
'dsn' => '',
'hostname' => 'localhost',
'username' => 'unityAdmin',
'password' => '*****',
'database' => 'crm',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (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,
);

$db['default']['port'] = '3306'
I've tried the common fixes of changing pconnect and db_debug etc but nothing seems to be working. I'm pretty stumped and any help would be greatly appreciated. Not sure if this is an issue with code igniter itself or XAMPP or what.  Confused 

Including the MVC code here for reference.
 
Model:
PHP Code:
<?php

    
class News_model extends CI_Model {

        public function 
__construct(){

            
$this->load->database();

        }

        public function 
get_news($slug){

            if(
$slug === FALSE){

                
$query $this->db->get('news');

                return 
$query->result_array();

            }

            
$query $this->db->get_where('news', array('slug' => slug));

        }

    }

?>


Controller:
PHP Code:
<?php

    
class News extends CI_Controller {

        public function 
__construct() {

            
parent::__construct();

            
$this->load->model('News_model');

            
$this->load->helper('url_helper');

        }

        public function 
index(){

            
$data['news'] = $this->News_model->get_news();

            
$this->load->view('templates/header'$data);

            
$this->load->view('news/index'$data);

            
$this->load->view('templates/footer'$data);

        }

        public function 
view($slug NULL){

            
$data['news_item'] = $this->News_model->get_news($slug);

            if (empty(
$data['news_item'])){

                
show_404();

            }

            
$data['title'] = $data['news_item']['title'];

            
$this->load->view('templates/header'$data);

            
$this->load->view('news/view'$data);

            
$this->load->view('templates/footer'$data);

        }

    }

?>


Index View:
PHP Code:
<h2><?php echo $title?></h2>

<?php foreach ($news as $news_item): ?>

    <h3><?php echo $news_item['title']; ?> </h3>

    <div class="main">

        <?php echo $news_item['text']; ?>

    </div>

    <p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View Article</a></p>

<?php endforeach; ?>

Specific Post:
PHP Code:
<?php

    
echo '<h2>'.$news_item['title'].'</h2>';

    echo 
$news_item['text'];

?>
Reply


Messages In This Thread
Failing to connect to database - by IcyGrey - 02-21-2018, 01:57 PM
RE: Failing to connect to database - by IcyGrey - 02-22-2018, 03:29 AM
RE: Failing to connect to database - by IcyGrey - 02-22-2018, 04:35 AM
RE: Failing to connect to database - by adhzim - 03-03-2021, 08:12 AM
RE: Failing to connect to database - by InsiteFX - 02-22-2018, 05:09 AM
RE: Failing to connect to database - by InsiteFX - 03-03-2021, 12:14 PM
RE: Failing to connect to database - by InsiteFX - 03-23-2021, 03:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB