dongpan9760 2011-11-23 20: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-24 00: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条)

报告相同问题?

悬赏问题

  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真