-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.php
70 lines (56 loc) · 1.8 KB
/
database.php
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
<?php
ini_set("dispaly_errors", 1);
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include 'Query.php';
$query = new Query();
$query->find("user");
$query->username = 'my_username';
$query->email = '[email protected]';
$query->status = 1;
$query->name = "Andy Name";
//$result = $query->save();
//echo "<pre>";
//print_r($result);
//echo 'my id is:' . $query->id . ' and my name is ' . $query->name . ' and table name is ' . $query->table;
//$delete = new Query();
//echo $delete->find("user")->where(['status' => 1])->deleteAll();
$qr = new Query();
$models = $qr->find("user")
->where(['status' => 1])
//->andFilterWhere(['IN', 'id', [1, 2, 3, 4, 5, 6, 7, 9, 10, 11]])
->orFilterWhere(['LIKE', 'name', '%Andy%'])
->all()
;
//echo $models->statement();
//->all();
if ($models)
foreach ($models as $model) {
// echo 'id is : ' . $model->id . 'name is :' . $model->name . ' and username is ' . $model->username . ' <p>';
}
$rs = new Query();
$rs->find("user");
$rs->hasOne([
'role' => [
//select name from table role where id = user.roleId
'find' => 'role',
'select' => 'name',
'where' => ['id' => 'roleId'],
],
// 'statuses' => [
// //select name from status where id = user.status
// 'find' => 'status',
// 'select' => 'name',
// 'where' => ['id' => 'user.status'],
// ]
]);
$res = $rs->all();
if ($res)
foreach ($res as $r) {
echo 'id is : ' . $r->id . 'name is :' . $r->name . ' and role is ' .$r->role->name . print_r($r->role) . ' <p>';
}
echo "<pre>";
print_r($rs->_relation);