//实例化表格,参数 int : 最大行数
$table = new swoole_table(1024);
//设置表格字段 参数 (字段名:string , 字段类型:int、float、string , 长度:int)
$table->column('id',$table::TYPE_INT,4);
$table->column('name',$table::TYPE_STRING,64);
$table->column('price',$table::TYPE_INT,11);
//创建表格
$table->create();
//添加数据 两种方式
$table->set('iphoneX',['id'=>1,'name'=>'iphoneX','price'=>9999]);
$table['xiaomi'] = ['id'=>2,'name'=>"小米",'price'=>3339];
foreach ($table as $key => $value) {
var_dump($value);
echo PHP_EOL ;
}
//单独设置某字段自增 参数('表名',’字段名‘,’步长‘)
$table->incr('iphoneX','price',1000);
var_dump($table->get('iphoneX'));
//单独设置字段自减
$table->decr('xiaomi','price',1000);
var_dump($table->get('xiaomi'));
//删除某条数据
$table->del('xiaomi');
//判断数据是否存在
if(!$table->exist('xiaomi')){
echo '不存在此字段';
}