1
這個邏輯有什麼問題?mysql node js quest - SELECT EXISTS查詢
var selectString = 'SELECT EXISTS(SELECT 1 FROM users WHERE user="'+username+'")';
var queryUserExists = connection.query(selectString);
var resultsLength = queryUserExists._results.length;
console.log(queryUserExists);
if(resultsLength > 0){
socket.write("fail user already exists"+"\r\n");
} else {
console.log('insert=');
var query = connection.query (
'INSERT INTO users '+
'SET user = ?, password = ?, token = ?',
[username, password, token]
);
socket.write("success"+"\r\n");
}
resultsLength總是返回零。 什麼是使用此查詢的正確方法?
返回的對象:
sql: 'SELECT 1 FROM users WHERE user = \'a new user is my name\' ORDER BY user LIMIT 1',
typeCast: true,
nestTables: false,
_resultSet: null,
_results: [],
_fields: [],
_index: 0,
_loadError: null }
我該如何在節點中使用它? – stackOverFlew
很高興知道關於性能的評論,雖然 – stackOverFlew
@ user1392515 - 抱歉替換'var selectString ='查詢我發佈了';' –