php - 使用 idiorm 和 php 更新一行

标签 php mysql idiorm

我有更新记录的功能,但我不能失败并向我发送“行中缺少主键 ID 或为空”消息,我该如何解决?

public static function update_child($data)
{
    try
    {
        $update= ORM::for_table("dm_child",DM_TAG)
                        ->where_equal($data["id_child"]);

        $update -> set(array(
            "gender" => $data["gender"]
            "age_year" =>$data["year"]
            "age_month" => $data["month"]

        ));
        $update -> save();
    }
    catch(PDOException $ex)
    {
        ORM::get_db()->rollBack();
        throw $ex;
    }
}

最佳答案

Idiorm 假定主键的名称是“id”,但在您的情况下并非如此。 因此,您必须明确地将其指定为 Idiorm:

<?php
    ORM::configure('id_column_overrides', array(
    'dm_child' => 'id_child',
    'other_table' => 'id_table',
));

参见 Docs>Configuration .

关于php - 使用 idiorm 和 php 更新一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27911939/

相关文章:

php - INSERT 和 UPDATE 语句将错误数据传递到数据库

php - 将 php session 变量序列化为 json 格式

php - 以安全的方式向服务器发送密码

php - "Unknown database type json requested, Doctrine\DBAL\Platforms\MySQL57Platform may not support it."运行 php artisan migrate 命令时

mysql - 替换select语句mysql中不同位置的多个关键字

php - ORM 类的对象无法使用 Idiorm 转换为字符串

mysql - 检索每个组中的最后一条记录 - MySQL

mysql - 如何创建将数据存储到 mysql 数据库的 angularjs springboot 应用程序。使用 json

php - 数据库名称 PDO 问题

php - 非主键自增字段