CodeIgniter Forums
use of Unique in mySQL field cases Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: use of Unique in mySQL field cases Error (/showthread.php?tid=77115)

Pages: 1 2 3


RE: use of Unique in mySQL field cases Error - richb201 - 07-27-2020

I am trying to use this one again in MyModel:
public function insertIgnore(array $data)
{
$_prepared = array();
foreach ($data as $col => $val)
{
$_prepared[$this->db->_escape_identifiers($col)] = $this->db->escape($val);
}
$this->db->query('INSERT IGNORE INTO `exclude_choices` ('.implode(',',array_keys($_prepared)).') VALUES('.implode(',',array_values($_prepared)).');');
}

I modified $_prepared[_escape_identifiers($col)] = escape($val); to get rid of the $this->db. Now I get "call to undefined function _escape_identifiers()".

Any idea?


RE: use of Unique in mySQL field cases Error - InsiteFX - 07-27-2020

PHP Code:
// Usage:

// Use this if the database is not loaded
// or autoloaded.
$this->load->database();

$table 'titles';

$data = array(
    'item'     => $post_array['employee_title'],
    'campaign' => $this->session->userdata('campaign'),
    'userid'   => $this->session->userdata('userid')
);

$sql $this->db->set($data)->get_compiled_insert($table);
$sql str_replace('INSERT INTO''INSERT IGNORE INTO'$sql);
$this->db->query($sql); 

You should not need to load the database if it is autoloaded.


RE: use of Unique in mySQL field cases Error - richb201 - 07-27-2020

OK. Tried using db-> as per your suggestion and it seems to work. Thanks again....


RE: use of Unique in mySQL field cases Error - InsiteFX - 07-27-2020

If it's working make sure you change the title of this post to [SOLVED] for others.