'INSERT INTO' 没有向我的 sql 数据库插入数据
'INSERT INTO' does not insert data to my sql database
我使用 wamp 服务器浏览数据库,我从 nodejs express 服务器开始连接数据库
当我写插入查询时没有错误,但是当我浏览 table 时,添加的行有空值。
这是我的查询代码
app.post('/new_sess_mouse',function(req,res ){
var sess_name = req.body.sess_name ,
sess_id = req.session.id ,
email = req.session.email ;
var sql = "INSERT INTO ?? SET ?? = ? AND ?? = ? AND ?? = ? ";
var inserts = ['sessions', 'sess_name' , sess_name ,'sess_id',sess_id ,'email' , email ];
sql = mysql.format(sql, inserts);
console.log(sql);
connection.query( sql , function( err , results ){
if(err) {
console.log(err.message);
}
else {
//connection.destroy();
console.log('succes');
}
}); });
当我打印出结果时
{ fieldCount: 0,
affectedRows: 1,
insertId: 0,
serverStatus: 2,
warningCount: 3,
message: '',
protocol41: true,
changedRows: 0 }
你的INSERT
语句格式有误。
你可以:
var sql = "INSERT INTO ?? ( ??, ??, ??) VALUES (?, ?, ?)";
var inserts = ['sessions', 'sess_name' , 'sess_id', 'email', sess_name , sess_id , email ];
或:
var sql = "INSERT INTO ?? SET ?? = ? , ?? = ? , ?? = ? ";
var inserts = ['sessions', 'sess_name' , sess_name ,'sess_id',sess_id ,'email' , email ];
我使用 wamp 服务器浏览数据库,我从 nodejs express 服务器开始连接数据库
当我写插入查询时没有错误,但是当我浏览 table 时,添加的行有空值。
这是我的查询代码
app.post('/new_sess_mouse',function(req,res ){
var sess_name = req.body.sess_name ,
sess_id = req.session.id ,
email = req.session.email ;
var sql = "INSERT INTO ?? SET ?? = ? AND ?? = ? AND ?? = ? ";
var inserts = ['sessions', 'sess_name' , sess_name ,'sess_id',sess_id ,'email' , email ];
sql = mysql.format(sql, inserts);
console.log(sql);
connection.query( sql , function( err , results ){
if(err) {
console.log(err.message);
}
else {
//connection.destroy();
console.log('succes');
}
}); });
当我打印出结果时
{ fieldCount: 0,
affectedRows: 1,
insertId: 0,
serverStatus: 2,
warningCount: 3,
message: '',
protocol41: true,
changedRows: 0 }
你的INSERT
语句格式有误。
你可以:
var sql = "INSERT INTO ?? ( ??, ??, ??) VALUES (?, ?, ?)";
var inserts = ['sessions', 'sess_name' , 'sess_id', 'email', sess_name , sess_id , email ];
或:
var sql = "INSERT INTO ?? SET ?? = ? , ?? = ? , ?? = ? ";
var inserts = ['sessions', 'sess_name' , sess_name ,'sess_id',sess_id ,'email' , email ];