【问题标题】:Codeigniter / Eloquent selecting but not insertingCodeigniter / Eloquent 选择但不插入
【发布时间】:2017-08-16 16:05:34
【问题描述】:

我已经按照 this(法语)和 this 教程在 CodeIgniter 3 应用程序中使用 Eloquent。

选择方法按预期工作,即使有关系,但插入/更新方法不起作用,也没有返回任何错误。我一直在寻找类似的问题,但无法解决我的问题,所以我希望有人能帮助我。

我的一个模特:

<?php

require_once('Eloquent.php');

use \Illuminate\Database\Eloquent\Model as Eloquent;

class User extends Eloquent { 

    //Eloquent vars
    public $table = "app_users";
    protected $primaryKey = "id";
    public $timestamps = false;
}

返回 1 但实际上并未将数据插入数据库的插入:

  $client = new User;
  $client->id = $id;
  $client->username = 'username';
  $client->first_name = 'first_name';
  $client->last_name = 'last_name';
  $client->mail = 'mail';
  $result = $client->save();

插入静默失败......任何提示将不胜感激,无论是关于如何解决这个问题或调试它! find()、all() 等方法再次运行正常,因此 Eloquent 似乎运行正常...

【问题讨论】:

  • 那么您实际使用哪种方法来建立连接。法语版本似乎是手动创建 PDO 连接。在这种情况下,您可能需要设置异常模式:$pdosetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - 默认为 PDO::ERRMODE_SILENT -(请参阅docs)
  • PHP 错误是什么意思(十五个字符)?

标签: php mysql codeigniter insert eloquent


【解决方案1】:

感谢Paul Spiegel 指出我需要修改异常模式(我错过了导致插入/更新失败的数据库迁移)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 2015-08-03
    • 2018-12-07
    • 1970-01-01
    • 2011-11-14
    • 2012-07-02
    相关资源
    最近更新 更多