0

Error Received:

Error Number: 1366

Incorrect string value: '\xCC_a' for column 'last_name' at row 1

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'

Filename: /Library/WebServer/Documents/PHP-Point-Of-Sale/models/person.php

Line Number: 85

Code:

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

Database column uses utf8_unicode_ci encoding

I tried using utf8_encode, but that didn't work

Krumelur
  • 31,081
  • 7
  • 77
  • 119
Chris Muench
  • 17,444
  • 70
  • 209
  • 362

1 Answers1

1

You have a problem with your encode. To solve that you should invoke the function utf8_encode on the value before store, like that.

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

I use CodeIgniter also, and the database configuration is:

$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
Pablo Ezequiel Leone
  • 1,337
  • 17
  • 22