My goal is to query MySQL with Node.JS for better interactivity. My query is a simple SELECT with JOINs. I managed to construct a script that displays results in the console but I'm kind of stuck when it comes to display it in the webpage. Here is my code:
var mysql = require('mysql');
var mySqlClient = mysql.createConnection({
host : 'server',
user : 'login',
password: 'pwd',
database: 'db'
});
var selectQuery = 'SELECT fields FROM table t1\
INNER JOIN table t2\
ON t1.field = t2.field';
mySqlClient.query(
selectQuery,
function select(error, results, fields) {
if(error) {
console.log(error);
mySqlClient.end();
return;
}
if(results.length > 0) {
console.log(results);
} else {
console.log('No data');
}
mySqlClient.end();
});
What is the best approach to include this into the webpage? Do I need to create a httpServer with Node.JS?
Many thanks for any help!
EDIT I would like to use Node.JS inside a PHP application designed with Zend Framework. The Node.JS app wouldn't be the sole app of my project.