Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Connect to an external database
- $db = Craft::createComponent([
- 'emulatePrepare' => true,
- 'charset' => 'utf8',
- 'class' => 'CraftDbConnection',
- 'autoConnect' => true,
- ]);
- $db->connectionString = 'mysql:host=localhost;dbname=MY_DB;port=3306';
- $db->username = 'UN';
- $db->password = 'PW';
- // Use Query Builder to fetch data from the database
- $data = $db->createCommand()
- ->select("*")
- ->from("TBL")
- ->queryAll();
- // Pass along the data to be used in a template via variables
- return $data;
Add Comment
Please, Sign In to add comment