• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Database Error while connecting from Localhost

#1
I'm fairly new to development and I'm completely new to codeigniter.
I've downloaded a CodeIgniter project from my company's server that I inherited from a previous developer.

I need to add a new page to the site. Since I'm new to CI, I (obviously) don't want to edit the live site but I can't get the site to run locally. I'm trying to run it on a local server either through MAMP or through the PHP server in terminal on a Mac running Yosemite 10.10.5.
I've added the project folder to htdocs in MAMP but when I open http://localhost:8888/index.php/contact the screen is blank. When I try to access the same folder through the terminal using:

Code:
env DB_USER=XXXX DB_PASSWD=XXXX DB_NAME=XXXX php -S localhost:8080

(where 'XXXX' is replaced with our database username and password)

I get the following error:


Quote:Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346

Line 346 of core/Loader.php is the public function database in the attached image.

Things I've tried:
  • I've tried changing the $config["base_url'] to "http://localhost:8888/'; but I still get the same error
  • Deleting the hostname, username and password from the database.php file, still get the same error
I'm not sure why a local version can't access a database when the live site can with the same login credentials? 

Any help is much appreciated as I just started this new position, this is one of my first projects for the company and it has me stumped. I still need to figure out how to add a page, but I can't even get the site loaded locally so I can work on it.

Thanks
Reply

#2
Check out the error logs (either in your server log folder or in CI's log folder /application/logs).
Reply

#3
(04-08-2017, 09:08 PM)SDillon001 Wrote: I'm fairly new to development and I'm completely new to codeigniter.
I've downloaded a CodeIgniter project from my company's server that I inherited from a previous developer.

I need to add a new page to the site. Since I'm new to CI, I (obviously) don't want to edit the live site but I can't get the site to run locally. I'm trying to run it on a local server either through MAMP or through the PHP server in terminal on a Mac running Yosemite 10.10.5.
I've added the project folder to htdocs in MAMP but when I open http://localhost:8888/index.php/contact the screen is blank. When I try to access the same folder through the terminal using:

Code:
env DB_USER=XXXX DB_PASSWD=XXXX DB_NAME=XXXX php -S localhost:8080

(where 'XXXX' is replaced with our database username and password)

I get the following error:


Quote:Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346

Line 346 of core/Loader.php is the public function database in the attached image.

Things I've tried:
  • I've tried changing the $config["base_url'] to "http://localhost:8888/'; but I still get the same error
  • Deleting the hostname, username and password from the database.php file, still get the same error
I'm not sure why a local version can't access a database when the live site can with the same login credentials? 

Any help is much appreciated as I just started this new position, this is one of my first projects for the company and it has me stumped. I still need to figure out how to add a page, but I can't even get the site loaded locally so I can work on it.

Thanks

Have you import the database file to your database server?
Reply

#4
(04-09-2017, 01:16 AM)janudewangga Wrote:
(04-08-2017, 09:08 PM)SDillon001 Wrote: I'm fairly new to development and I'm completely new to codeigniter.
I've downloaded a CodeIgniter project from my company's server that I inherited from a previous developer.

I need to add a new page to the site. Since I'm new to CI, I (obviously) don't want to edit the live site but I can't get the site to run locally. I'm trying to run it on a local server either through MAMP or through the PHP server in terminal on a Mac running Yosemite 10.10.5.
I've added the project folder to htdocs in MAMP but when I open http://localhost:8888/index.php/contact the screen is blank. When I try to access the same folder through the terminal using:

Code:
env DB_USER=XXXX DB_PASSWD=XXXX DB_NAME=XXXX php -S localhost:8080

(where 'XXXX' is replaced with our database username and password)

I get the following error:


Quote:Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346

Line 346 of core/Loader.php is the public function database in the attached image.

Things I've tried:
  • I've tried changing the $config["base_url'] to "http://localhost:8888/'; but I still get the same error
  • Deleting the hostname, username and password from the database.php file, still get the same error
I'm not sure why a local version can't access a database when the live site can with the same login credentials? 

Any help is much appreciated as I just started this new position, this is one of my first projects for the company and it has me stumped. I still need to figure out how to add a page, but I can't even get the site loaded locally so I can work on it.

Thanks

Have you import the database file to your database server?

No, I haven't imported the database to my local computer, I'm trying to connect to the live database that the live website connects to......? Is that possible? Or do I need to import it since I'm trying to view the site on a local server?
Reply

#5
**Update**

I downloaded a copy of my live database from the server to my local computer but I still can't access it. I tried removing the user and password (leaving the DB name) and still nothing. Any thoughts?
Reply

#6
Make sure you're connecting using localhost details. Usually:

Host: localhost
User: root
Pass:
Reply

#7
(04-09-2017, 08:38 PM)JayAdra Wrote: Make sure you're connecting using localhost details. Usually:

Host: localhost
User: root
Pass:

Thanks Jay, I did try that. It looks like my database connection has been customized. Here's what my `database.php` file looks like.....it's not setup as an array (image also attached):


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

  $db['default']['hostname'] = 'localhost';
  $db['default']['username'] = 'root';
  $db['default']['password'] = '';
  $db['default']['database'] = 'database_name'; // contains actual name
  $db['default']['dbdriver'] = 'mysqli';
  $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;


Attached Files Thumbnail(s)
   
Reply

#8
Did you check the error logs? What's the exact error you're getting?
Reply

#9
(04-10-2017, 02:35 AM)JayAdra Wrote: Did you check the error logs? What's the exact error you're getting?


Here are 2 links to videos to hopefully explain / illustrate better what I'm working with and the error I'm getting. I have the database file inside the project folder......? I'm not sure why that's there or what to do with it.

Link #1 - Trying to run on built-in PHP server and / or MAMP: https://youtu.be/5p43JyROUOs

Link #2 - Database file in Project Folder:  https://youtu.be/A7I2VEQPXtg
Reply

#10
Sorry, I'm not sure how to check the error logs for the built-in PHP server?

Thanks again for your help!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.