Nick F
Nick F

Reputation: 10112

FuelPHP "invalid data source name" error

I'm trying to set up a FuelPHP app, and I've run into a puzzling problem. Every time the app tries to connect to the database, I get the following error:

Fuel\Core\Database_Exception [ Error ]: invalid data source name

I've set FUEL_ENV to "stage" in Apache's VirtalHost configuration and the database credentials in fuel/app/config/staging/db.php seem to be correct: I can log in to PhpMyAdmin using the same username and password. I'm stumped as to what else to try - any advice would be much appreciated.

In case it helps, I'm using FuelPHP 1.4 on an Amazon EC2 instance running Ubuntu 12.04 LTS on which I've installed MySQL and PHP via apt-get. I have another app (on another instance) running an older version of FuelPHP (1.2.1) which runs with no problems.

Incidentally, this question is probably closely related to this one, but I'm asking it as a separate question because the problem I'm having is not limited to the command line.

Upvotes: 2

Views: 3447

Answers (4)

locrizak
locrizak

Reputation: 12281

For those of you who none of this worked make sure of two things

  1. there are multiple db.php files /fuel/app/config/development/db.php. check environment as @Chad Hutchins mentioned and double check the username and password is correct
  2. Make sure /var/mysql/mysql.sock exists. In my case I was using /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock so i needed to create a symlink. Followed the instructions here

Hope that helps someone

Upvotes: -1

Chad Hutchins
Chad Hutchins

Reputation: 484

I had the same issue when running unit tests with FuelPHP's oil utility. If you're running into this issue, it most likely is a configuration issue.

To debug, somewhere in the code that isn't working put something like the following to see what environment FuelPHP is trying to use:

<?php

echo "env: " . Fuel::$env; 
exit;

In my case, it showed it was trying to use the 'Test' environment. Since I didn't have a 'test' folder in my app's config folder, it was failing.

In most versions of FuelPHP, however you have the Fuel::$env set in your .htaccess file will work throughout all versions of FuelPHP. However in older versions, you may run into this issue.

You can either edit the bootstrap.php file and manually set the FuelPHP environment how you want, or setup the environment that it's trying to use.

Upvotes: 0

Nick F
Nick F

Reputation: 10112

Ok, this has taken far too long to get to the bottom of, but it turns out to be simple to fix: for some reason, in FuelPHP 1.4 the stage environment's config directory is called staging (in previous versions it was stage).

I don't know whether this is a directory naming mistake, or whether this is a new name and something somewhere in FuelPHP hasn't been updated to use it, but I found changing the directory's name to 'stage' fixed the problem.

Upvotes: 3

MrTechie
MrTechie

Reputation: 1847

Apache web server: SetEnv FUEL_ENV DEVELOPMENT Hope this helps someone

Upvotes: -1

Related Questions