-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.html
100 lines (92 loc) · 2.27 KB
/
update.html
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
93
94
95
96
97
98
99
100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="Stylesheet" type="text/css" href="style.css">
<title>数据库操作类update</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript" type="text/javascript" src="scripts/shCore.js"></script>
<link rel="stylesheet" href="styles/shCoreDjango.css" type="text/css" media="screen" charset="utf-8">
<script src="scripts/shBrushPhp.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
SyntaxHighlighter.all();
</script>
</head>
<body>
<h1 id="toc_1">update()</h1>
<ul>
<li>
update($id='',$arr=array());函数参数是主键的一个值或者使用前面指定的查询条件,返回bool
<li>
Sample code
</ul>
<p>
<strong>使用对象方式:</strong>
</p>
<ul>
<li>
1.按照主键更新
<pre class="brush:php">
public function update()
{
$user=M('user');
$user->db->name='小红';
$user->db->email='[email protected]';
$user->db->update(1);
}
</pre>
<li>
2.按照条件更新
<pre class="brush:php">
public function update()
{
$user=M('user');
$user->db->name='小红';
$user->db->email='[email protected]';
$user->db->where('name="小明"')->update();
}
</pre>
或者使用数组更新条件:
<pre class="brush:php">
public function update()
{
$user=M('user');
$user->db->name='小红';
$user->db->email='[email protected]';
$condition['name']='小明';
$condition['email']='[email protected]';
$user->db->where($condition)->update();
}
</pre>
</ul>
<p>
<strong>使用数组方式</strong>:
</p>
<ul>
<li>
按照主键更新:
<pre class="brush:php">
public function foo()
{
$user=M('user');
$data['name']='xiaoming';
$data['email']='[email protected]';
$user->db->update(1,$data);
}
</pre>
<li>
按照条件更新:
<pre class="brush:php">
public function foo()
{
$user=M('user');
$data['name']='xiaoming';
$data['email']='[email protected]';
$user->db->where('name="小胖"')->update($data);
}
</pre>
</ul>
<p>
<div align="center"><a href="getNum.html">上一页</a> <a href="index.html">首页目录</a> <a href="delete.html">下一页</a></div>
</p>
</body>
</html>