fetch data from mysql db with js or java, no php usage

which is the best approach to open connection to a db that is on another domain with js, java.
Example, im using gtm to push data to a datalyer, all i have is front-end access, but i have access to the data base on another domain, how can i fetch the data from the other data base to gtm when gtm only allows js no php coding, so the date can be dynamic since the data that i need to push is coming from the external database.
Thanks in advance
<script>

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
 document.write(rs.fields(1));
  rs.movenext;
}

rs.close;
connection.close;

    dataLayer.push({
  'usersigendup': 'some-value',
    'productID2': 'some-value2',
    'productID3': 'some-value3',
 });

 </script>

The above code isnt working, but basically how can i accomplish that "some-value" become the result of a value fecthed from the DB.that is what i found so far googling

GTM has no serverside API for tracking, so you cannot send data directly (also you do not want to give database credentials to a client-side script).
You could create a serverside script that fetches data from your database.  Then you make this available via an URL that returns the database result. Then you create a custom HTML tag with a JavaScript that connects to your new endpoint, fetches the response and parses it into variables that you then use in your tracking tags. 
You would need to make sure that your script still works (or terminates properly) when there is no response from your endpoint. 
Simo Ahava demonstrated the technique in an older article of his, the only difference is that instead of using an availaibe webservice like the weather API you would have to create your own service that returns your database results.