简体   繁体   English

PHP-CodeIgniter-DataMapper-save()错误

[英]PHP - CodeIgniter - DataMapper - error with save()

I tried to make a model with DataMapper, but when I used save() to insert some new data, it returns an error. 我尝试使用DataMapper建立模型,但是当我使用save()插入一些新数据时,它将返回错误。

Error 错误

A Database Error Occurred 发生数据库错误

You must use the "set" method to update an entry. 您必须使用“设置”方法来更新条目。

Filename: C:\\wamp\\www\\website\\system\\database\\DB_active_rec.php 档案名称:C:\\ wamp \\ www \\ website \\ system \\ database \\ DB_active_rec.php

Line Number: 1174 行号:1174

I have an ID in the database with auto-increment , and I used the method inscription from a controller. 我的数据库中有一个ID为auto-increment ,并且使用了控制器的方法题字。

Code

<?php

    class Utilisateur_model extends DataMapper {

        var $table = 'utilisateur';

        var $validation = array(

            'login' => array(

                'label' => 'Login',
                'rules' => array('required', 'unique', 'trim')
            ),
            'mdp' => array(

                'label' => 'Mot de passe',
                'rules' => array('required', 'trim')
            ),
            'nom_utilisateur' => array(

                'label' => 'Nom',
                'rules' => array('required', 'trim')
            ),
            'prenom_utilisateur' => array(

                'label' => 'Prenom',
                'rules' => array('required', 'trim')
            ),
            'email' => array(

                'label' => 'Email',
                'rules' => array('required', 'valid_email', 'trim')
            ),
            'adresse' => array(

                'label' => 'Adresse',
                'rules' => array('required', 'trim')
            )
        );


        public static function inscription($donnees) {

            $u = new Utilisateur_model();

            $u->login = $donnees['login'];
            $u->mdp = $donnees['mdp'];
            $u->nom_utilisateur = $donnees['nom'];
            $u->prenom_utilisateur = $donnees['prenom'];
            $u->email = $donnees['email'];
            $u->adresse = $donnees['adresse'];

            if($u->save()) {

                return array(true);
            }
            else {

                return array(false, $u->error->string);
            }
        }
    }
?>

The line 1174 is in this method : 1174行就是这种方法:

function insert($table = '', $set = NULL)
{
    if ( ! is_null($set))
    {
        $this->set($set);
    }

    if (count($this->ar_set) == 0)
    {
        if ($this->db_debug)
        {
            return $this->display_error('db_must_use_set'); //line 1174
        }
        return FALSE;
    }

    if ($table == '')
    {
        if ( ! isset($this->ar_from[0]))
        {
            if ($this->db_debug)
            {
                return $this->display_error('db_must_set_table');
            }
            return FALSE;
        }

        $table = $this->ar_from[0];
    }

    $sql = $this->_insert($this->_protect_identifiers($table, TRUE, NULL, FALSE), array_keys($this->ar_set), array_values($this->ar_set));

    $this->_reset_write();
    return $this->query($sql);
}

好的,我找出原因了...因为数据库中的列名全部大写,而模型中的列名全部为小写...但是现在工作了:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM