[英]php phalcon phql update
I am new to phalcon framework.I would like to update data from phalcon model update method. 我是phalcon框架的新手,我想通过phalcon模型更新方法更新数据。
$sql = "UPDATE
table
SETcol1
='1',col2
= NULL WHERE 1";$ sql =“ UPDATE
table
SETcol1
='1',col2
= NULL WHERE 1”;
to 至
> $all = model::findFirst();
> $all->col1 = '1';
> $all->col2= NULL;
> $all->update();
I have no idea about for "where 1" . 我不知道“ where 1”。
Before you can update a model you need to request it from the database. 在更新模型之前,您需要从数据库中请求它。
In the following example you are querying the first record where the value in column col1
equals 123
. 在以下示例中,您要查询第一个记录,其中
col1
列中的值等于123
。
$all = model::findFirst(['col1 = 123']);
// you can also write this like
$all = model::findFirstByCol1(123);
In the background Phalcon will convert the above code to a query, similar to: Phalcon将在后台将上面的代码转换为查询,类似于:
SELECT * FROM model WHERE col1 = 123 LIMIT 1;
SELECT * FROM model WHERE col1 = 123 LIMIT 1;
Now that you have access to the model via $all
, you can alter its attributes: 现在您可以通过
$all
访问模型,可以更改其属性:
$all->col2 = null;
If you are done altering $all
, you can update the values in the database: 如果完成
$all
修改,则可以更新数据库中的值:
$all->update(); // or $all->save();
Refer to the Phalcon documentation , if you need more help on working with models. 如果您在使用模型方面需要更多帮助,请参考Phalcon文档 。
What is this WHERE 1
? 这是
WHERE 1
? You mean WHERE id = 1
? 您的意思是
WHERE id = 1
? Then you need: 然后,您需要:
$all = model::findFirst(1);
$all->col1 = '1';
$all->col2= NULL;
$all->update();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.