EJS is a java code generator. You can import any existing java library and use it with EJS.
So if you include java library for mysql , you will be able to execute sql statement with function call and do what you want.
I know that it can be done. But I have never try it.  So I do not have example to share with you.

You can also use AJAX to get the data and send those data to EJS with java script call. For example: snapshot of the simulation was generated this way. Javascript code call public method in EJS and EJS generate snapshot image and return  as data. Then image data sent to php script to create image file. And you can access database with php script easily.
I think this in-direct method will be easier to implement.