你可以輪詢這樣的答案,因爲我從來沒有使用過mysql節點的庫。
行計數間隔
變種連接= ..., lastCount;
funciton mysqlPoll() {
var query = connection.query('SELECT count(field) as count FROM table');
query.exec(function(result) {
if (result.count != lastCount) {
//Select all the rows here using offset to skip the already processes
//process them
lastCount = result.count;
}
});
}
setInterval(mysqlPoll, 500); //every 1/2 second
,如果你有一個主自動INC鍵間隔
var connection = ...,
lastCount = 0;
funciton mysqlPoll() {
var query = connection.query('SELECT * FROM table WHERE primaryId > '+lastCount);
query.exec(function(result) {
if (result.count != lastCount) {
//Select all the rows here using offset to skip the already processes
//process them
lastCount = lastResultsPrimaryId;
}
});
}
setInterval(mysqlPoll, 500); //every 1/2 second
另一種選擇是打開一個套接字(淨值,HTTP等),對Node.js和受平更好它從php腳本觸發更新。
希望有幫助
所以基本上你想JavaScript來知道什麼時候插入一個新行?爲什麼不把你的功能綁定到插入行的函數?這樣,你總是知道何時放置一個新的行。 – Joseph
嗯,我正在讀取由另一個表更新mysql觸發器創建的表。基本上我想顯示實時更新。它們是由PHP腳本創建的 – sauletasmiestas
然後,如果你在你的文章中解釋說你不是唯一使用db並希望從它獲得更新的人。否則,每個人都可以假設只有你的應用程序正在使用它。 – Joseph