0

I am working with CodeIgniter and want to return some values using a distinct query, I am not able to change the collation in the database itself, and can not do so in the config either, as I am changing somebody else's code.

Is there a way to collate within a query using Active Record? So far I have tried:

$this->db->select('fieldName COLLATE utf8_bin');

I have also attempted to use $this->db->collator_set_default to no avail.

Alfie Goodacre
  • 2,753
  • 1
  • 13
  • 26

1 Answers1

2

Try to read over the manual https://codeigniter.com/user_guide/database/configuration.html

In the default connection array you can find fields

'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',

Might go also with a code while the query is run

$this->db->query("SET NAMES 'latin1'");
$this->db->insert('table_name', $data);
Kavvson Empcraft
  • 445
  • 7
  • 32
  • Sorry, I have stated that I can not edit the config, this includes database.php, thank you anyway :) – Alfie Goodacre Mar 22 '16 at 15:06
  • Uhm I see. You can try like $this->db->query("SET NAMES 'latin1'"); and then your query $this->db->insert('table_name', $data);, might help – Kavvson Empcraft Mar 22 '16 at 15:08
  • I am not inserting into the database, I am trying to select without being case-insensitive, which means that I have to collate For example with a table that contains "this" and "This", `SELECT DISTINCT name COLLATE utf8_bin FROM table` would return both "this" and "This", whereas without the COLLATE, it would only return "this" or "This" – Alfie Goodacre Mar 22 '16 at 15:13
  • Give it a try or maybe try to convert the output with http://php.net/manual/en/function.mb-convert-encoding.php idk what can help:) – Kavvson Empcraft Mar 22 '16 at 15:15