Codeigniter数据库错误:1064使用MySQL,可能还有一些会话配置错误 [英] Codeigniter Database Error : 1064 Using MySQL and maybe some session config error

查看:75
本文介绍了Codeigniter数据库错误:1064使用MySQL,可能还有一些会话配置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用Codeigniter 3.xx,并且尝试使用会话检查进行多级登录。我从另一个网站上获得了一些教程,但是查询出错。
顺便说一下,这是为控制者准备的:

I'm currently using Codeigniter 3.xx and I trying to make a multilevel login using session checking. I got some tutorial from another website, but there's an error with query. By the way this is for the controler :

    <?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Auth extends CI_Controller {

    public function index() {
        $this->load->view('login');
    }

    public function cek_login() {
        $data = array('nip' => $this->input->post('nip'),
                        'password' => $this->input->post('password')
            );
        $this->load->model('user_m'); 
        $hasil = $this->user_m->cek_user($data);
        if ($hasil->num_rows() == 1) {
            foreach ($hasil->result() as $sess) {
                $sess_data['logged_in'] = 'Sudah Loggin';
                $sess_data['nip'] = $sess->nip;
                $sess_data['akses'] = $sess->akses;
                $this->session->set_userdata($sess_data);
            }
            if ($this->session->userdata('akses')=='admin') {
                redirect('admin');
            }
            elseif ($this->session->userdata('akses')=='member') {
                redirect('user');
            }       
        }
        else {
            echo "<script>alert('Gagal login: Cek username, password!');history.go(-1);</script>";
        }
    }

}

?>

这是控制器的模型:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

    class User_m extends CI_Model {

        public function cek_user($data) {
            $query = $this->db->get_where(`pegawai`, $data);
            return $query;
        }

    }

?>

然后我收到此错误:

错误号:1064
您的SQL语法有错误;检查与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在'WHERE nip ='21212121'AND 密码 ='user'在第二行
选择* WHERE nip ='21212121'和密码 ='用户'
文件名:C:/xampp/htdocs/simpeg/application/models/User_m.php
行号:7

Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE nip = '21212121' AND password = 'user'' at line 2 SELECT * WHERE nip = '21212121' AND password = 'user' Filename: C:/xampp/htdocs/simpeg/application/models/User_m.php Line Number: 7

我知道我没有为此表使用MariaDB Engine,如果该表运行正常,则应以用户身份登录。
谁能解释这个语法有什么问题吗?
顺便说一下,我在此项目中使用最新的XAMPP for PHP 7和Codeigniter

The things that I know I don't use MariaDB Engine for this table, and it should be logged in as user if that run correctly. Can anybody explain what was the wrong with this syntax? By the way I'm using newest XAMPP for PHP 7 and Codeigniter in this project

更新 >
在尝试了一些代码之后,我认为会话配置存在一些问题。
这是我用于会话的config.php:

UPDATE After I tried some code, I thought that I have some problem with the session configuration. This is my config.php for session:

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

这是我在Session.php中系统文件夹中的配置:

And this is my configuration in Session.php in system folder :

class CI_Session {

    var $sess_encrypt_cookie        = FALSE;
    var $sess_use_database          = FALSE;
    var $sess_table_name            = '';
    var $sess_expiration            = 7200;
    var $sess_expire_on_close       = FALSE;
    var $sess_match_ip              = FALSE;
    var $sess_match_useragent       = TRUE;
    var $sess_cookie_name           = 'ci_session';
    var $cookie_prefix              = '';
    var $cookie_path                = '';
    var $cookie_domain              = '';
    var $cookie_secure              = FALSE;
    var $sess_time_to_update        = 300;
    var $encryption_key             = '';
    var $flashdata_key              = 'flash';
    var $time_reference             = 'time';
    var $gc_probability             = 5;
    var $userdata                   = array();
    var $CI;
    var $now;

在新版本的Codeigniter(我使用的版本)中,每当我尝试自动加载会话时,要求我为会话添加一些加密密钥,所以在我输入加密密钥后,关于会话的查询中将出现如下错误:
错误编号:1064
您的错误SQL语法;查看与您的MariaDB服务器版本相对应的手册以获取正确的语法,以在'SET last_activity = 1455761673, user_data 附近使用='a:2:{s:9:\ user_data\; s:0:\ \'在第1行
UPDATE SET last_activity = 1455761673, user_data ='a:2:{s:9:\ user_data\; s:0:\ \; s:3:\ nip\; s:10:\ 1234567890\;}'WHERE session_id ='316bdf2f67b16beafbe30b56bca3833d'
文件名:librarys / Session.php
行号:306

In the new version of Codeigniter (which one I use), whenever I tried to autoload session there always asked me to put some encryption key for the session, so after I put the encryption key there's an error in the query about session like this: Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SET last_activity = 1455761673, user_data = 'a:2:{s:9:\"user_data\";s:0:\"\"' at line 1 UPDATE SET last_activity = 1455761673, user_data = 'a:2:{s:9:\"user_data\";s:0:\"\";s:3:\"nip\";s:10:\"1234567890\";}' WHERE session_id = '316bdf2f67b16beafbe30b56bca3833d' Filename: libraries/Session.php Line Number: 306

推荐答案

对不起,我找到了我问题的答案...
我尝试再次下载最新的Codeigniter,并将其替换到我的项目中,然后重新配置我的项目后,结果我的查询已读取并成功执行,但是会议没有。所以我尝试调试我的代码2天,发现(大约15分钟前)我的管理员/用户控制器中有些奇怪的东西,没有定义<?php。 ')OR exit('不允许直接脚本访问'); 而是<?php session_start(); ,所以我将其更改并出现问题解决了。哦,如果有人找到

I'm sorry but, I've found the answer for my problem... After I tried to download newest Codeigniter again, and replace it in my project, and re-config my project, in result my query was read and successful executed, but the session didn't. So I tried to debug my code for 2 days, and I found (just about 15 minutes ago) there's something strange in my controller for admin/user, there wasn't <?php defined('BASEPATH') OR exit('No direct script access allowed'); but instead <?php session_start(); so I changed it and problem solved. Oh if anyone found


libraries / Session.php

libraries/Session.php

删除它!

这是我遇到此错误的第一个原因

That's the first reason that I have this error


错误号:1064您的SQL语法错误;检查与您的MariaDB服务器版本相对应的
手册,以在
第2行的'WHERE nip ='21212121'AND password ='user'附近使用正确的
语法选择SELECT * WHERE nip ='21212121'AND密码='user'文件名:
C:/xampp/htdocs/simpeg/application/models/User_m.php行号:7

Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE nip = '21212121' AND password = 'user'' at line 2 SELECT * WHERE nip = '21212121' AND password = 'user' Filename: C:/xampp/htdocs/simpeg/application/models/User_m.php Line Number: 7

感谢所有帮助过我的人...:D

Thanks for you all who helped me... :D

这篇关于Codeigniter数据库错误:1064使用MySQL,可能还有一些会话配置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆