Not sure if this is the best solution, but it works for MySQLi:
Code:
//Get the Connection info from X-Cart 5
$xc_conn = \XLite\Core\Database::getEM()->getConnection();
//Collect the info you need for a MySQLi connection
$sql_host =$xc_conn->getHost();
$sql_db =$xc_conn->getDatabase();
$sql_user =$xc_conn->getUsername();
$sql_password =$xc_conn->getPassword();
//Collect your data using MySQLi
$conn = new mysqli($sql_host, $sql_user, $sql_password,$sql_db);
if ($conn->connect_error) {
error_log('MySQLi could not connect: ' . $conn->connect_error);
}
$sql_query = "SELECT * FROM YourTable";
$db_results = $conn->query($sql_query);
$results_array = $db_results->fetch_assoc();
if ($db_results->num_rows > 0) {
foreach($results_array as $dbkey=>$dbvalue) {
echo 'Key: '.$dbkey.' = '.$dbvalue.'<br />';
}
}
Hope that helps!