Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using DB class in tasks?
  • I am running some tasks from cron but I am having problem using DB class in tasks. I get this error and just can't figure out what's wrong?

    2002 - SQLSTATE[HY000] [2002] No such file or directory in COREPATH/classes/database/pdo/connection.php on line 94

    My task code:

    namespace Fuel\Tasks;

    class Mytask
    {
        public function run()
        {
            \Cli::write('Hello word');
        }

        public function test()
        {
            $result = \DB::query('SELECT 1 as test')->execute();
        }
    }

    Running this via command line php oil refine Mytask:test
  • Sounds like a socket issue? On a Mac by any chance?
  • Hi Harro,

    correct, running on a Mac yes (OS X 10.10.1)...

  • You are right again, it has to do something with Mac. Running fine on production Linux server ... 
  • The Mac's PHP setup is configured with a custom location for your php.ini. Which causes php-cli, used by oil, to read the wrong file, which misses all database information.

    It's a common problem on the Mac, see if you can locale all php.ini files on disk and sort it out. There are several other threads about this issue.
  • Ok I understand that. Is there a way to tell php-cli which php.ini file to use? Or at list find out which one is used?
  • I don't have a Mac myself, so I can't really help you with that.

    I assume the trick is to find the one that is used by apache (because that works), and swap the others by a symlink to the working version. So essentially you only have one real file, that is used everywhere.

    you can specify the ini file to use on the commandline, but I don't think you want to type it in every day...
  • Hey Jume, Mac user here ;)

    you can find out what ini files are
    being used/loaded/parsed by $ php using the --cli flag. For your case
    the problem is another. See the following site
    http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-9-mavericks/#mysql
    => "Fix the 2002 MySQL Socket error".

    From that page:
    Fix
    the looming 2002 socket error – which is linking where MySQL places the
    socket and where OSX thinks it should be, MySQL puts it in /tmp and OSX
    looks for it in /var/mysql the socket is a type of file that allows
    mysql client/server communication.
    $ sudo mkdir /var/mysql
    $ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
  • @philipptempel thanks for you update on this, but this does not fix my problem... I am still having the same 2002 error :/

    2002 - SQLSTATE[HY000] [2002] No such file or directory in COREPATH/classes/database/pdo/connection.php on line 94


    But your answer helped me reach solution with the help of this question on stack overflow. I had to locate the right mysql.sock file and then do what you suggested. It worked, thanks a lot!


    In your terminal try something like: locate mysql | grep sock

    You will get something like: http:///the/path/to/mysql.sock

    Then do: ln -s /the/path/to/mysql.sock /tmp/mysql.sock

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion