1
  • Craft Version 3.2
  • PHP Version 7.2

Below is my folder structure:

Root
  - Other Craft Folder
  - Web
     - Services
         - Db.php
     - env file

I want to read the connection string of the SQL SERVER from the env file.

Things I have already tried:

  1. App::env
  2. require_once 'C:\wamp64\www\craftApp\vendor\autoload.php'; use craft\helpers\App;
print_r(Craft::parseEnv('$sqlServerName')); // Throws Error

But it doesn't work.

1

If that is really all that you're doing, and you have no other integration with Craft, you can parse the .env however you like. Craft uses vlucas/phpdotenv internally so that library is already in your vendor directory. You should be able to pick that up after including Composer's autoloader.

If however you have any kind if integration with Craft, look at web/index.php and see what's going on in terms of bootstrapping there, copying the parts necessary for your application.

2
  • I have also update my general.php to include additional environment settings. But I'm not able to access below Craft::$app->getConfig()->getGeneral() – Deepak Kale May 17 at 9:09
  • Where are you calling Craft::$app->getConfig()->getGeneral() from, though? – Andy May 17 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.