0
最初の関数がテーブルにデータを挿入する2つの関数を呼び出しています。私はmysql
を使用しています。 2番目はtheの値を数えて表示します。ノードループ内に挿入して選択しても動作しない
問題は、2番目の機能はテーブルを挿入する前に処理していることです。私は何をやっているのですか?
私のコードは次のとおりです。
function_my(id);
console.log('id inserted');
count(id);
function_my(id){
var mysql = require('mysql2');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'gcm',
});
for(var id=0; j < 10; j++){
connection.query('INSERT INTO UserTable SET ?', {id : id}, function(err, res){
if(err) throw err;
});
}
count(id){
connection.execute('select id from UserTable where id = ?', id , function(err, rows){
console.log('Test :'+JSON.stringify(rows[0].id));
});
}
出力は次のようになります。
Test : undefined
Id inserted
がなぜ問題に直面していますか?