I am running PHP in node (Why not experimenting I know its crazy) to retrieve some data using ODBC connection.
This is the node server
Webserver.js
var express = require('express');
var app = express();
var R = require('ramda');
var execPHP = require('./execphp.js')();
execPHP.phpFolder='C:\\users\\public\\data\\';
app.use('*.php', function(request,response,next) {
execPHP.parseFile(re
quest.originalUrl,function(phpResult) {
var phpData = response.write(phpResult);
response.end();
});
});
app.listen(3000, function () {
console.log('Node server listening on port 3000!');
});
Executes PHP
execphp.js
/**
*
*/
class ExecPHP {
/**
*
*/
constructor() {
this.phpPath = 'C:/php/php.exe';
this.phpFolder = '';
}
/**
*
*/
parseFile(fileName,callback) {
var realFileName = this.phpFolder + fileName;
console.log('parsing file: ' + realFileName);
var exec = require('child_process').exec;
var cmd = this.phpPath + ' ' + realFileName;
exec(cmd, function(error, stdout, stderr) {
callback(stdout);
});
}
}
module.exports = function() {
return new ExecPHP();
};
php data
$connect = odbc_connect("sqltest", "", "");
$query = "SELECT [Mand]
,[Category]
,[Course]
FROM [Trt].[dbo].[ListViewMain]";
# perform the query
$result = odbc_exec($connect, $query);
# fetch the data from the database
while(odbc_fetch_row($result)){
$MandStat = odbc_result($result, 1);
$Category = odbc_result($result, 2);
$Course= odbc_result($result, 3);
print("$Mand $Category $Course\n");
}
# close the connection
odbc_close($connect);
?>
My questiong would be how do i get the data from my localhost:3000/data.php to my index.html
What would be the best approach to solve this issue?