|
写了个简单的记录打开次数
ifaction发生get请求,无条件记录数据- <div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;"><div><span style="color: #66d9ef;font-style: italic;">var</span> web <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"http://127.0.0.1/?id=1"</span></div><div> IWeb.<span style="color: #a6e22e;">getUrl</span>(web)</div></div>
复制代码
node
- <div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><span style="color: #66d9ef;font-style: italic;">var</span> getmysql <span style="color: #f92672;">=</span> <span style="color: #66d9ef;">require</span>(<span style="color: #e6db74;">"../get/cateController"</span>)</div></div><div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;">router.<span style="color: #a6e22e;">get</span>(<span style="color: #e6db74;">'/'</span>, getmysql.getgame)</div><div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><div><span style="color: #66d9ef;font-style: italic;">var</span> jishiqi <span style="color: #f92672;">=</span> <span style="color: #ae81ff;">0</span></div><div><span style="color: #66d9ef;font-style: italic;">var</span> chaxun <span style="color: #f92672;">=</span> <span style="color: #ae81ff;">0</span></div><div><span style="color: #a6e22e;">newone</span> <span style="color: #f92672;">=</span> () <span style="color: #66d9ef;font-style: italic;">=></span>{</div><div> <span style="color: #66d9ef;font-style: italic;">var</span> sql <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"SELECT id FROM game"</span></div><div> <span style="color: #66d9ef;font-style: italic;">var</span> sqlArr <span style="color: #f92672;">=</span> [];</div><div> <span style="color: #66d9ef;font-style: italic;">var</span> <span style="color: #a6e22e;">callBack</span> <span style="color: #f92672;">=</span> (<span style="color: #fd971f;font-style: italic;">err</span>,<span style="color: #fd971f;font-style: italic;">data</span>)<span style="color: #66d9ef;font-style: italic;">=></span>{</div><div> <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(data)</div><div> <span style="color: #66d9ef;font-style: italic;">var</span> sqlcmd <span style="color: #f92672;">=</span> <span style="color: #66d9ef;">JSON</span>.<span style="color: #66d9ef;">stringify</span>(data)</div><div> <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(sqlcmd)</div><div> <span style="color: #66d9ef;font-style: italic;">var</span> sqlcmd1 <span style="color: #f92672;">=</span> <span style="color: #66d9ef;">JSON</span>.<span style="color: #66d9ef;">parse</span>(sqlcmd)</div><div> <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(sqlcmd1[<span style="color: #ae81ff;">0</span>].id)</div><div> chaxun <span style="color: #f92672;">=</span> sqlcmd1[<span style="color: #ae81ff;">0</span>].id</div><div> }</div><div> </div><div> dbCongif.<span style="color: #a6e22e;">sqlConnect</span>(sql,sqlArr,callBack)</div><div>}</div><div><span style="color: #88846f;">// sql读取数据初始化计数器</span></div><div><span style="color: #a6e22e;">newone</span>()</div><div><span style="color: #a6e22e;">getgame</span> <span style="color: #f92672;">=</span> (<span style="color: #fd971f;font-style: italic;">req</span>,<span style="color: #fd971f;font-style: italic;">res</span>)<span style="color: #66d9ef;font-style: italic;">=></span>{</div><div> chaxun<span style="color: #f92672;">++</span></div><div> <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(chaxun)</div><div> <span style="color: #66d9ef;font-style: italic;">var</span> sql <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"UPDATE `game` SET `id`="</span><span style="color: #f92672;">+</span>chaxun<span style="color: #f92672;">+</span><span style="color: #e6db74;">""</span></div><div> <span style="color: #66d9ef;font-style: italic;">var</span> sqlArr <span style="color: #f92672;">=</span> [];</div><div> <span style="color: #66d9ef;font-style: italic;">var</span> <span style="color: #a6e22e;">callBack</span> <span style="color: #f92672;">=</span> (<span style="color: #fd971f;font-style: italic;">err</span>,<span style="color: #fd971f;font-style: italic;">data</span>)<span style="color: #66d9ef;font-style: italic;">=></span>{</div><div> <span style="color: #f92672;">if</span>(err){</div><div> <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(<span style="color: #e6db74;">"sql错误无法初始化sql池"</span>)</div><div> }<span style="color: #f92672;">else</span>(</div><div> res.<span style="color: #a6e22e;">send</span>({</div><div> <span style="color: #e6db74;">"cishu"</span>:data</div><div> })</div><div> )</div><div> <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(<span style="color: #e6db74;">"数据传输完成 "</span><span style="color: #f92672;">+</span>jishiqi<span style="color: #f92672;">+</span><span style="color: #e6db74;">" 次"</span>);</div><div> jishiqi<span style="color: #f92672;">++</span></div><div>}</div><div>dbCongif.<span style="color: #a6e22e;">sqlConnect</span>(sql,sqlArr,callBack)</div>
- <div>}</div><div><span style="color: #88846f;">// 相应数据变化</span></div>
- <div><span style="color: #66d9ef;font-style: italic;">module</span>.<span style="color: #66d9ef;font-style: italic;">exports</span> <span style="color: #f92672;">=</span> {</div><div> getgame,</div><div>}</div></div></div>
复制代码
源代码:https://epiphylluminlove.lanzous.com/iPe9Xhg8mwf
实况
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|