您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman常用组件-MySQL组件-workerman之使用Workerman-MySQL - 具体MySQL的Connection用法-獲取一行數據
发布时间:2021-12-21 22:47:42编辑:雪饮阅读()
實例:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onWorkerStart = function($worker)
{
global $db;
// 初始化db连接
$db = new \Workerman\MySQL\Connection('127.0.0.1', '3306', 'xy', 'xy', 'workerman');
};
$worker->onMessage = function(TcpConnection $connection, $data)
{
global $db;
$response=[];
// 获取一行数据
$response["row1"]=$db->select('ID,newstext')->from('phome_ecms_news_data_1')->where('classid<>:classid and newstext=:newstext')->bindValues(array('classid'=>81,"newstext"=>"雪饮"))->row();
//等价于
$response["row2"]=$db->select('ID,newstext')->from('phome_ecms_news_data_1')->where("classid<>81 and newstext='雪饮'")->row();
//等价于
$response["row3"]=$db->row("SELECT ID,newstext FROM `phome_ecms_news_data_1` WHERE classid<>81 and newstext='雪饮'");
$connection->send(json_encode($response));
};
// 运行worker
Worker::runAll();
关键字词:Workerman,MySQL,Connection,一行
上一篇:workerman常用组件-MySQL组件-workerman之使用Workerman-MySQL - 具体MySQL的Connection用法-獲取所有數據
下一篇:workerman常用组件-MySQL组件-workerman之使用Workerman-MySQL - 具体MySQL的Connection用法-獲取一列數據
相关文章
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之使用Workerm
- workerman常用组件-MySQL组件-workerman之安装 Worker
- workerman常用组件-MySQL组件-workerman之mysql-pdo_m
- workerman常用组件-FileMonitor文件监控组件
- workerman常用组件-channel分佈式通訊組件-channelCli
- workerman常用组件-channel分佈式通訊組件-channelCli
- workerman常用组件-channel分佈式通訊組件-channelCli
- workerman常用组件-channel分佈式通訊組件-channelCli
- workerman常用组件-channel分佈式通訊組件-channelCli