字符串值不正确:列的'\ xCC_a'

时间:2012-10-21 22:35:08

标签: php mysql

收到错误:

  

错误号码:1366

字符串值不正确:列的'\ xCC_a'   第1行的'last_name'

     

UPDATE phppos_people SET first_name ='Juan Gordon',last_name =   'Garc _a',email ='EMAIL@email.com',phone_number ='',   address_1 ='',address_2 ='',city ='',state ='',zip =   '',country ='',comments =''WHERE person_id =   '238'

文件名:   /Library/WebServer/Documents/PHP-Point-Of-Sale/models/person.php

Line   数量:85

代码:

//Skip first row
fgetcsv($handle);
while (($data = fgetcsv($handle)) !== FALSE) 
{
    $person_data = array(
    'first_name'=>$data[0],
    'last_name'=>$data[1],
    'email'=>$data[2],
    'phone_number'=>$data[3],
    'address_1'=>$data[4],
    'address_2'=>$data[5],
    'city'=>$data[6],
    'state'=>$data[7],
    'zip'=>$data[8],
    'country'=>$data[9],
    'comments'=>$data[10]
    );

    $customer_data=array(
    'account_number'=>$data[11]=='' ? null:$data[11],
    'taxable'=>$data[12]=='' ? 0:1,
    'company_name' => $data[13],
    );
    if($this->Customer->exists($data[14]))
    {
        $this->Customer->save($person_data,$customer_data,$data[14]);
    }
    else if(!$this->Customer->save($person_data,$customer_data))
    {   
        echo json_encode( array('success'=>false,'message'=>lang('customers_duplicate_account_id')));
        return;
    }
}

数据库列使用utf8_unicode_ci编码

我尝试使用utf8_encode,但这不起作用

1 个答案:

答案 0 :(得分:1)

您的编码有问题。要解决这个问题,你应该在存储之前调用函数utf8_encode,就像那样。

$person_data = array(
'first_name' => $data[0],
'last_name'  => utf8_encode($data[1]),
...

我也使用CodeIgniter,数据库配置为:

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';