This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引用MySQL函式庫 | |
var mysql = require('mysql'); | |
// 建立資料庫連線池 | |
var pool = mysql.createPool({ | |
user: '資料庫帳號', | |
password: '資料庫密碼', | |
host: '主機位置', | |
port: '資料庫port' | |
database: '資料庫名稱', | |
// 無可用連線時是否等待pool連線釋放(預設為true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 新增當地時區的時間物件 | |
function DateTimezone(offset) { | |
// 建立現在時間的物件 | |
d = new Date(); | |
// 取得 UTC time | |
utc = d.getTime() + (d.getTimezoneOffset() * 60000); | |
// 新增不同時區的日期資料 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"lastUpload":"2020-03-24T03:32:23.893Z","extensionVersion":"v3.4.3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 關閉資料庫連線 | |
connection.end(function(err) { | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 引用MySQL函式庫 | |
var mysql = require('mysql'); | |
// 資料庫設定 | |
var db_config = { | |
user: '資料庫帳號', | |
password: '資料庫密碼', | |
host: '主機位置', | |
port: '資料庫port' | |
database: '資料庫名稱' | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 連線Memcache | |
$meminstance = new Memcache(); | |
$meminstance->pconnect('localhost', 11211); | |
// 存放資料到Memcache | |
$cache_key = 'hello_memcache'; | |
$cache_data = 'cache_info'; | |
$meminstance->set($cache_key, $cache_data, 0, 600); | |
// 讀取Memcached存放的資料 | |
$res = $meminstance->get($cache_key); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('send', function(msg) { | |
// 廣播資訊給在socket.room的人,除了發送者自己 | |
socket.broadcast.to(socket.room).emit('updatechat', msg); | |
// 傳送更新資訊給自己 | |
socket.emit('updatechat', msg); | |
socket.to(socket.room).emit('updatechat', msg); | |
// 傳送資訊給所有socket | |
io.sockets.emit('updatechat', msg); | |
// 傳送資訊給在socket.room的連線 | |
io.sockets.in(socket.room).emit('updatechat', msg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 找捷運台北車站附近距離2公里內的捷運站、依照建立時間做排序、找前3筆資料 | |
db.lbs_test.aggregate( | |
{ | |
$geoNear : { | |
near : [25.046084,121.517542], | |
distanceField : "dist", | |
maxDistance : 2 / 111.12 | |
} | |
}, | |
{ |
NewerOlder