想學(xué)習(xí)一下如何使用workerman gateway中使用數(shù)據(jù)庫的例子。
看了幾個(gè)項(xiàng)目,好像都沒有用到。比如聊天室。
我是這么寫的,可以參考下~~
public static function sendOffLineMessage($uid){
$dbData = Db::instance('dbData');
$data = $dbData->select('*')->from('chat_log')->where('toUserId= :toUserId')->where('status= :status')->orderBy(array('addTime'))->bindValues(array('toUserId'=>$uid,'status'=>2))->query();
foreach($data as $v){
$new_message = array(
'type'=>'3',
'targetUserId'=>$v,
'content'=>$v,
'addTime'=>$v,
'contentType'=>$v,
);
Gateway::sendToUid($v, json_encode($new_message));
$dbData->update('chat_log')->cols(array('status'))->where('id='.$v)->bindValue('status',1)->query();
}
return;
}