0

i am new to node.js and my boss has entrusted me with a job to integrate a notification system in our attendance project.. so far i have successfully created a connection to my data base using express and mysql node modules and the code that helped me in achieving that is given below

var express=require('express');
var mysql=require('mysql');
var app=express();
var connection=mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'',
    database:'attendance'
});
connection.connect(function(error) {
    if(!!error) {
        console.log('Error in connection');
    } else {
        console.log('Connected');  
    }
});
app.get('/',function (req, resp) {
    connection.query("Select * from employee_leaves", function (error, rows, fields) {
        if (!!error) {
            console.log("Error in the query");
        } else {
            console.log("successfully done\n");
            console.log(rows);
        }
    });
})

app.listen(1337); 

// now the issue is i want to query this statement

SELECT * from employee_leaves WHERE employee_leave_company_name ='$sup_company_name' AND leave_status='Pending'ORDER BY employee_leave_id desc"

the issue is these variable $sup_company_name is in php so

1) how should i fetch value from that variable

2)how to use where clause in node.js

Note:: $sup_company_name is declared in my require.php file the code of require.php file is given below P.S i m accessing that variable in my other pages by include('require.php') but i dont know how to access that variable in node.js

session_start();
$sup_id = $_SESSION['employee_id'];
$sup_type=$_SESSION['employee_type'];
$sup_company_name=$_SESSION['employee_company_name'];    
alex
  • 5,467
  • 4
  • 33
  • 43
iqra
  • 115
  • 1
  • 12
  • I think you and your boss must read module docs - https://github.com/mysqljs/mysql#escaping-query-values . Read a little bit articles about Node/Express before use it. Node is not php. – Aikon Mogwai Jul 29 '16 at 10:11
  • @AikonMogwai ok i understood that but how to access $sup_company_name in my .js file i am trying to say is lets suppose i ameliorate my query to connection.query('SELECT * FROM employee_leaves WHERE employe_company_name = ?', [company_name], function(err, results) my question is how should i fetch value from $sup_company_name and store it in var company_name – iqra Jul 29 '16 at 10:15
  • Session variables available by `req.session`. To use `sessions` in Express you must `var session = require('express-session'); app.use(session({ ..params.. }))` and read doc - https://github.com/expressjs/session – Aikon Mogwai Jul 29 '16 at 10:33

0 Answers0