方脸的路飞 发表于 2016-3-8 09:39:22

ci 数据库问题

Error Number: 1146La table 'test.user' n'existe pasSELECT * FROM `user` WHERE `email` IS NULLFilename: F:/wamp/www/application/models/login_model.phpLine Number: 15


Aloghli 发表于 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";

Hex 发表于 2016-3-8 10:44:03

贴代码看看

方脸的路飞 发表于 2016-3-8 11:12:13

Hex 发表于 2016-3-8 10:44
贴代码看看

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;
          }
          
        }
?>

Hex 发表于 2016-3-8 12:40:29

看起来没问题呀。。。。
你那个错误应该是 SQL 写的有问题。

方脸的路飞 发表于 2016-3-8 12:43:38

Hex 发表于 2016-3-8 12:40
看起来没问题呀。。。。
你那个错误应该是 SQL 写的有问题。

不会呀,我在数据库中试过的没问题呀。请问您的qq是多少,我想详细问问

Hex 发表于 2016-3-8 13:24:07

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

49489680
页: [1]
查看完整版本: ci 数据库问题