For PHP, there is a v8js extension that allows you to run Javascript code and get the result.
The question is - is it possible to access a database (for example, MySQL) from within this Javascript code?
Well, you can register js-extensions for your database (if any) through V8Js::registerExtension, which you can pull out, for example, through file_get_contents, and then work with the database through it.