X-Cart 5 uses Doctrine library to work with the database. Although it works with its own tables via the ORM part of the library, you still can execute raw SQL queries over database tables created by other applications - see the documentation on createNativeQuery() method there:
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html
To get the entity manager that works with the XC5's database, do this:
PHP Code:
$entityManager = \XLite\Core\Database::getEM();
To work with other databases (created by other web applications) you can create custom "entity managers" - check how X-Cart 5 creates its own entity manager in \XLite\Core\Database::startEntityManager() method.