dongpan9760 2011-11-23 12:44
浏览 24
已采纳

如何在巴黎进行“查找和更新”查询

I am using Paris with Idiorm and I am having problems finding in the documentation a clear instruction on how to find and update a table.

I don't want to insert a sql query into the script. Is there any other way?

Paris is an Active Record implementation based on Idiorm. Idiorm is an object-relational mapper and fluent query builder.

I am interested in doing something like count = count + 1 all in one go

  • 写回答

2条回答 默认 最新

  • dqlb38410 2011-11-23 16:07
    关注

    I found this on their github site:

    Updating records To update the database, change one or more of the properties of the object, then call the save method to commit the changes to the database. Again, you can change the values of the object's properties either by using the set method or by setting the value of the property directly:

    $person = ORM::for_table('person')->find_one(5);
    
    // The following two forms are equivalent
    $person->set('name', 'Bob Smith');
    $person->age = 20;
    
    // Syncronise the object with the database
    $person->save();
    Creating new records
    

    To add a new record, you need to first create an "empty" object instance. You then set values on the object as normal, and save it.

    $person = ORM::for_table('person')->create();
    
    $person->name = 'Joe Bloggs';
    $person->age = 40;
    
    $person->save();
    

    After the object has been saved, you can call its id() method to find the autogenerated primary key value that the database assigned to it.

    Checking whether a property has been modified To check whether a property has been changed since the object was created (or last saved), call the is_dirty method:

    $name_has_changed = $person->is_dirty('name'); // Returns true or false
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥20 对文档进行操作,有偿 有意向的可以加我v
  • ¥15 brainstorm进行致痫指数分析
  • ¥30 beeline连接hive集群会卡住
  • ¥15 julia语言画表面图
  • ¥15 前端css轮播图效果优化
  • ¥15 如何在已有的土地利用类型图中加入新的地类呢
  • ¥20 TCIA数据库下载报错,请问如何解决
  • ¥30 vue3使用@imgly/background-removal给图片去除背景
  • ¥15 从mysql导入数据到hive
  • ¥15 海康视频线上无法正常播放