You are not logged in.
Pages: 1
Is it possible to connect to an external database on the back end of a module?
I added the database credentials through environment.php
// External Database
$bigtree["config"]["ex"]["host"] = "";
$bigtree["config"]["ex"]["name"] = "";
$bigtree["config"]["ex"]["user"] = "";
$bigtree["config"]["ex"]["password"] = "";
$bigtree["config"]["ex"]["port"] = "3306";
$bigtree["config"]["ex"]["socket"] = "";
custom/inc/modules/connect.php,
I want to connect to an external database and tried connecting in "public function __construct()".
When I try to pull from the external table, I get the error
Fatal error: Uncaught mysqli_sql_exception: Table 'localhost.audience' doesn't exist
Its still looking at localhost database.
Offline
You can't use the built in SQL helper functions to access a separate database but you should be able to create a MySQLi connection yourself and access it that way.
e.g.
$db = new mysqli($bigtree["config"]["ex"]["host"], $bigtree["config"]["ex"]["user"], $bigtree["config"]["ex"]["password"], $bigtree["config"]["ex"]["name"]);
$query = $db->query("SELECT * FROM whatever");
while ($row = $query->fetch_assoc()) {
/// do something;
}
Offline
Pages: 1