# Mysql具體使用
**異步mysql連接池**
例子可參考ServerMysqlTest.php文件
## 創建表
示例:
```php
yield $this->mysql_pool->dbQueryBuilder->coroutineSend(null, "
CREATE TABLE IF NOT EXISTS `MysqlTest` (
`peopleid` smallint(6) NOT NULL AUTO_INCREMENT,
`firstname` char(50) NOT NULL,
`lastname` char(50) NOT NULL,
`age` smallint(6) NOT NULL,
`townid` smallint(6) NOT NULL,
PRIMARY KEY (`peopleid`),
UNIQUE KEY `unique_fname_lname`(`firstname`,`lastname`),
KEY `fname_lname_age` (`firstname`,`lastname`,`age`)
) ;
");
```
## 刪除表(直接執行sql語句)
示例:
```php
yield $this->mysql_pool->dbQueryBuilder->coroutineSend(null, "
DROP TABLE `MysqlTest`;
");
```
## 插入
示例:
```php
$value = yield $this->mysql_pool->dbQueryBuilder->insert('MysqlTest')
->option('HIGH_PRIORITY')
->set('firstname', 'White')
->set('lastname', 'Cat')
->set('age', '25')
->set('townid', '10000')
->coroutineSend();
```
## 替換
示例:
```php
$value = yield $this->mysql_pool->dbQueryBuilder->replace('MysqlTest')
->set('firstname', 'White')
->set('lastname', 'Cat')
->set('age', '26')
->set('townid', '10000')
->coroutineSend();
```
## 修改
示例:
```php
$value = yield $this->mysql_pool->dbQueryBuilder->update('MysqlTest')
->set('age', '20')
->where('townid', 10000)
->coroutineSend();
```
## Update 字段值的增加/減少
示例:
```php
$value = $this->db->update('MysqlTest')
->set("score","score+1",false)
->where('townid', 10000)->coroutineSend();
```
## 查詢
示例:
```php
$value = yield $this->mysql_pool->dbQueryBuilder->Select('*')
->from('MysqlTest')
->where('townid', 10000, "<")
->orderBy("townid","desc")
->limit(10)
->coroutineSend();
```
## 刪除
示例:
```php
$value = yield $this->mysql_pool->dbQueryBuilder->delete()
->from('MysqlTest')
->where('townid', 10000)
->coroutineSend();
```
## 返回值
[Mysql返回值說明](mysql返回值.md)
- Introduction
- SD 3.X文檔連接
- 導言
- 用戶案例
- 基于Swoole擴展分布式全棧開發框架
- 選擇SD框架助力企業開發
- 捐贈SwooleDistributed項目
- 框架性能報告
- 更新日志
- VIP服務福利
- 安裝與配置
- 【推薦】全自動安裝部署
- 環境要求
- 使用Composer安裝/更新SD框架
- 通過Docker安裝
- 代碼結構
- 啟動命令
- 服務器配置
- 服務器基礎配置server.php
- 客戶端協議配置client.php
- business.php
- log.php
- 微服務及集群配置consul.php
- fileHeader.php
- mysql.php
- redis.php
- 定時任務配置timerTask.php
- 服務器端口配置ports.php
- catCache.php
- 驗證服務啟動成功
- 微服務-Consul
- 日志工具-GrayLog
- 集群-Cluster
- 內核優化
- 入門教學
- 開發流程
- 開發前必讀
- 開發規范
- 基本流程
- 框架入口
- Model數據模型
- Controller控制器
- 協程
- 協程基礎
- 迭代器
- 調度器
- 使用協程的優勢
- 通過協程的方法屏蔽異步同步的區別
- Select多路選擇器
- 協程Sleep
- 通用協程方法
- 設置超時
- 設置無異常
- 設置降級函數
- initAsynPools
- dump
- 封裝器與路由器
- 封裝器
- sendToUid
- 路由器
- sendToUids
- 對象池
- 擴展組件
- 中間件
- Redis使用介紹
- RedisAsynPool
- Redis具體使用
- sendToAll
- RedisRoute
- Redis+Lua
- Mysql使用介紹
- MysqlAsynPool
- Mysql返回值
- 如何獲取構建的mysql語句
- 如何執行一個SQL
- 如何執行事務
- stopTask
- Mysql具體使用
- 異步客戶端
- Loader
- MqttClient
- model
- SdTcpRpcPool
- task
- HttpClientPool
- view
- TcpClientPool
- AMQP
- initialization
- Memory
- destory
- Cache
- Lock
- Pool
- EventDispatcher
- Process
- Cluster
- TimerTask
- Reload
- Consul
- Context
- 自定義進程
- 進程間RPC
- $http_input
- CatCache
- $http_output
- TimerCallBack
- 專題
- HTTP專欄
- TCP專欄
- 基礎知識
- WebSocket專欄
- 微服務
- Consul配置
- RPC
- REST
- AMQP異步任務系統
- MQTT簡易服務器
- Docker化以及資源編排
- 快速搭建公司內部統一的開發環境
- 使用HTTPS/WSS
- 訂閱/發布
- 游戲專題
- 類介紹
- AppServer
- clearState
- onOpenServiceInitialization
- SwooleDistributedServer
- get_instance
- kickUid
- bindUid
- unBindUid
- coroutineUidIsOnline
- coroutineCountOnline
- setTemplateEngine
- isWebSocket
- isTaskWorker
- getSocketName
- initAsynPools
- addAsynPool
- getAsynPool
- getServerAllTaskMessage
- Controller
- onExceptionHandle
- send
- sendToUid
- sendToUids
- sendToAll
- sendToGroup
- close
- getContext
- defaultMethod
- $redis_pool
- $mysql_pool
- $request_type
- $fd
- $uid
- $client_data
- $request
- $response
- $loader
- $logger
- $server
- $config
- Model
- initialization
- destory
- View
- Task
- stopTask
- HttpInput
- postGet
- post
- get
- getPost
- getAllPostGet
- getAllHeader
- getRawContent
- cookie
- getRequestHeader
- server信息
- getRequestMethod
- getRequestUri
- getPathInfo
- HttpOutput
- setStatusHeader
- setContentType
- setHeader
- end
- setCookie
- endFile
- 單元測試