用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2741|回复: 6
收起左侧

[讨论/交流] ci 数据库问题

[复制链接]
发表于 2016-3-8 09:39:22 | 显示全部楼层 |阅读模式

Error Number: 1146

La table 'test.user' n'existe pas

SELECT * FROM `user` WHERE `email` IS NULL

Filename: F:/wamp/www/application/models/login_model.php

Line Number: 15




发表于 2016-3-14 10:03:51 | 显示全部楼层
方脸的路飞 发表于 2016-3-8 11:12
database.php
$active_group = 'test';
$query_builder = TRUE;

哥们  模型定义数据库表 不是  var $table = "user";哦  应该是public $table = "user";
发表于 2016-3-8 10:44:03 | 显示全部楼层
贴代码看看
 楼主| 发表于 2016-3-8 11:12:13 | 显示全部楼层

database.php
$active_group = 'test';
$query_builder = TRUE;

$db['test'] = array(
        'dsn'        => '',
        'hostname' => 'localhost',
        'username' => 'root',
        'password' => '',
        'database' => 'test',
        'dbdriver' => 'mysqli',
        'dbprefix' => '',
        'pconnect' => TRUE,
        'db_debug' => TRUE,
        'cache_on' => FALSE,
        'cachedir' => '',
        'char_set' => 'utf8',
        'dbcollat' => 'utf8_general_ci',
        'swap_pre' => '',
        'encrypt' => FALSE,
        'compress' => FALSE,
        'stricton' => FALSE,
        'failover' => array(),
        'save_queries' => TRUE
);
控制器:
<?php
        /**
        *
        */
        class Login extends CI_Controller
        {
               
                public function __construct(){
                parent::__construct();
                $this->load->model('login_model');
                $this->load->helper('url');
                $this->load->helper('form');
                   }

                public function login()
                {
                        if (! file_exists(APPPATH.'/views/login/loginPage.php')) {
                                show_404();
                        }
                        if(isset($_POST)){
                                $email = $this->input->post('email');
                                $password = $this->input->post('password');
                                $data = $this->login_model->login($email);
                                if (!empty($data) && ($password === $data['password']) ) {
                                        redirect('success','refresh');
                                }
                                if (($email != $data['email'])||($password!=$data['password'])) {
                                        // redirect('fail','refresh');
                                }
                        }

                        $this->load->view('templates/header');
                        $this->load->view('login/loginPage',$data);
                        $this->load->view('templates/footer');
                }
        }

?>
模型:
<?php
        /**
        *
        */
        class Login_model extends CI_Model
        {
                var $table = "user";

                public function __construct(){
               
                $this->load->database();
            }
            //根据email查询数据
                public function login($email){
                $data = $this->db->from($this->table)->where(array('email'=>$email))->get()->row_array();
                return $data;
            }
            
        }
?>
发表于 2016-3-8 12:40:29 | 显示全部楼层
看起来没问题呀。。。。
你那个错误应该是 SQL 写的有问题。
 楼主| 发表于 2016-3-8 12:43:38 | 显示全部楼层
Hex 发表于 2016-3-8 12:40
看起来没问题呀。。。。
你那个错误应该是 SQL 写的有问题。

不会呀,我在数据库中试过的没问题呀。请问您的qq是多少,我想详细问问
发表于 2016-3-8 13:24:07 | 显示全部楼层
方脸的路飞 发表于 2016-3-8 12:43
不会呀,我在数据库中试过的没问题呀。请问您的qq是多少,我想详细问问

49489680

本版积分规则