<p>I may have found my own solution. It looks as if Yiic was not picking up the .env file.</p>

<p>The file ... craft\app\etc\console\yiic .. must therefore be changed from ...</p>

<pre><code>#!/usr/bin/env php
&lt;?php
require_once(dirname(__FILE__).'/yiic.php');
</code></pre>

<p>... to ...</p>

<pre><code>#!/usr/bin/env php
&lt;?php
require_once('../../../../vendor/autoload.php');
try {
    $dotenv = new Dotenv\Dotenv('../../../../');
    $dotenv-&gt;load();
    $dotenv-&gt;required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
} catch (Exception $e) {
    exit('Could not find a .env file.' . $e);
}
require_once(dirname(__FILE__).'/yiic.php');
</code></pre>

<p>Hope this is of use to other people.</p>

CC BY-SA 3.0
2017-06-29T15:14:59.997Z
2017-06-29T15:14:59.997Z
Martin Twigg
<p>I am running Craft 2 under MAMP (PHP 7.0.9) on windows and have a site that works under it. However if I use GIT to cd to the yiic console folder...</p>

<p><code>/c/mamp/htdocs/website/craft/app/etc/console</code></p>

<p>... and type ...</p>

<p><code>php yiic help</code></p>

<p>... I get an error message ...</p>

<p><code>Fatal error: Uncaught Error: Class 'Craft\ErrorHandler' not found in C:\MAMP\htdocs\website\craft\app\framework\YiiBase.php:213</code></p>

<p>... However, if I use PHP 5.6 (the one that I use to run the site - and which therefore has a different php.ini) I get a different message ...</p>

<p><code>exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected.</code></p>

<p>... even though the database settings must be OK as Craft works.</p>

<p>How do I get yiic to work?</p>

<hr>

<p>PS: I have put some debugging into <code>console\yiic.php</code> and the paths that are getting returned match what I would expect.</p>

<p>I have also looked at <a href="https://craftcms.stackexchange.com/questions/12557/error-connecting-to-mamp-pro-database-in-console-command">Error Connecting To (MAMP Pro) Database in Console Command</a> but the modification it suggests to <code>craft/config/db.php</code> refers to a file that does not exist: mysql.sock</p>

<yiic>
Running console (yiic) under MAMP (Windows)
# Running console (yiic) under MAMP (Windows)

(Asked by: username_0 on 2017-06-29)

I am running Craft 2 under MAMP (PHP 7.0.9) on windows and have a site that works under it. However if I use GIT to cd to the yiic console folder...

`/c/mamp/htdocs/website/craft/app/etc/console`

... and type ...

`php yiic help`

... I get an error message ...

`Fatal error: Uncaught Error: Class 'Craft\ErrorHandler' not found in C:\MAMP\htdocs\website\craft\app\framework\YiiBase.php:213`

... However, if I use PHP 5.6 (the one that I use to run the site - and which therefore has a different php.ini) I get a different message ...

`exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected.`

... even though the database settings must be OK as Craft works.

How do I get yiic to work?

---

PS: I have put some debugging into `console\yiic.php` and the paths that are getting returned match what I would expect.

I have also looked at [Error Connecting To (MAMP Pro) Database in Console Command](https://craftcms.stackexchange.com/questions/12557/error-connecting-to-mamp-pro-database-in-console-command) but the modification it suggests to `craft/config/db.php` refers to a file that does not exist: mysql.sock

**Tags:** yiic


---

## 1 answers

### Answer by username_0 on 2017-06-29. Score: 1

I may have found my own solution. It looks as if Yiic was not picking up the .env file.
The file ... craft\app\etc\console\yiic .. must therefore be changed from ...
#!/usr/bin/env php

... to ...
#!/usr/bin/env php
load();
    $dotenv->required(['DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS']);
} catch (Exception $e) {
    exit('Could not find a .env file.' . $e);
}
require_once(dirname(__FILE__).'/yiic.php');

Hope this is of use to other people.


---

