简体   繁体   English

Codeigniter活动记录中如何从SQL中选择Unicode文本?

[英]How to select unicode text from SQL in codeigniter active record?

I have a very basic, yet important question that I have been struggling with for over 2 hours now. 我有一个非常基本但重要的问题,我已经苦苦挣扎了两个多小时。

Question

How to force (N) prefix when selecting from MS-SQL using CodeIgniter active record? 使用CodeIgniter活动记录从MS-SQL中进行选择时,如何强制(N)前缀?

This is my code: 这是我的代码:

Controller: 控制器:

$result = $this->users->login($uname, $password);

Model 模型

function login($username = NULL, $password = NULL)
{
    if( !$username || !$password){          
        return FALSE;           
    }

    $this->db->select('CustomerID');
    $query = $this->db->get_where('UsersTbl',array('Username' => $username, 'Password' => $password));

    return $query->row_object();
}

Now, I have tried putting "N" before the $username in the model function call like: 现在,我尝试在模型函数调用中将$ username之前的“ N”放在:

array('Username' => 'N\\''.$username, 'Password' => $password)) , which constructs the SQL query as: WHERE Username = 'N'arabicText' array('Username' => 'N\\''.$username, 'Password' => $password)) ,它将SQL查询构造为: WHERE Username ='N'arabicText'

and tried putting the (N) after the field name, like the '<' or '>' trick in the form: 并尝试将(N)放在字段名称之后,例如格式中的'<'或'>'技巧:

array('Username=N' => $username, 'Password' => $password)) which constructs the SQL query as: WHERE Username =N 'arabicText' --> And for this to work, the (N) must be directly attached to the text, in the form: N'arabicText' array('Username=N' => $username, 'Password' => $password))将SQL查询构造为: WHERE Username = N'arabicText' ->为此,(N)必须为直接附加到文本的形式: N'arabicText'

It all seems to fail...any ideas?? 一切似乎都失败了...任何想法?

Ok, I found the answer. 好的,我找到了答案。

First: 第一:

Change the call in the model to: $query = $this->db->get_where('UsersTbl',array('Username = N' => $username, 'Password' => $password)); 将模型中的调用更改为: $query = $this->db->get_where('UsersTbl',array('Username = N' => $username, 'Password' => $password));

Second: 第二:

In codeigniter *System/database/DB_active_rec.php* I've changed the way SQL is contructed in line 427 they add space to the value of "where": $v = ' '.$this->escape($v) , Now I had to remove this space so that it becomes: $v = ''.$this->escape($v) or just $v = $this->escape($v) 在codeigniter * System / database / DB_active_rec.php *中,我已经更改了在第427行中构造SQL的方式,它们为“ where”的值添加了空间: $v = ' '.$this->escape($v) ,现在我必须删除此空间,使其变为: $v = ''.$this->escape($v)或仅$v = $this->escape($v)

Now when I check the $sql it self, it's just how I need it to be: SELECT CustomerID FROM UsersTbl WHERE Username = N'جاد' AND Password = '123' 现在,当我自行检查$ sql时,就正是我需要的方式: SELECT CustomerID FROM UsersTbl WHERE Username = N'جاد' AND Password = '123'

As you can see, the Password field is not affected by the change, because it only applies to the fields with operators =D 如您所见,“密码”字段不受更改影响,因为它仅适用于带有运算符= D的字段

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

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