forked from whcyc2002/swoole_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDb.php
More file actions
92 lines (79 loc) · 1.96 KB
/
Copy pathDb.php
File metadata and controls
92 lines (79 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace App\Controller;
use Swoole;
class Db extends Swoole\Controller
{
function apt_test()
{
$apt = new Swoole\SelectDB($this->db);
$apt->from('users');
$apt->equal('id', 1);
$res = $apt->getall();
var_dump($res);
}
function tables()
{
/**
* master database
*/
$tables = $this->db->query("show tables")->fetchall();
var_dump($tables);
/**
* other
*/
$tables = $this->db("huya")->query("show tables")->fetchall();
var_dump($tables);
}
function put()
{
$model = Model('User');
$id = $model->put(array('name' => 'swoole', 'level' => 5, 'mobile' => '19999990000'));
echo "insert id = $id\n";
}
function get()
{
$model = Model('User');
$user = $model->get(1);
/**
* 打印数组
*/
var_dump($user->get());
/**
* 修改mobile 为 13800008888
*/
$user->mobile = '13800008888';
$user->save();
//删除此条记录
//$user->delete();
}
function gets()
{
/**
* @var $model \App\Model\User
*/
$model = Model('User');
//level = 5
$gets['level'] = 5;
//仅获取数据
var_dump($model->gets($gets));
//分页
$gets['page'] = empty($_GET['page'])?1:intval($_GET['page']);
$gets['pagesize'] = 5;
$pager = null;
$list = $model->gets($gets, $pager);
foreach($list as $li)
{
echo "{$li['id']}: {$li['name']}<br/>\n";
}
//上一页/下一页
echo $pager->render();
}
function codb()
{
$ret1 = $this->codb->query("show tables");
$ret2 = $this->codb->query("desc user_login");
$this->codb->wait(1.0);
var_dump($ret1->result->fetchall());
var_dump($ret2->result->fetchall());
}
}