Welcome Guest, Not a member yet? Register   Sign In
use of Unique in mySQL field cases Error
#11

(This post was last modified: 07-23-2020, 09:15 AM by InsiteFX.)

Ok, here is another one I found that you can try.

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

$this->insertIgnore($data); 

Place this into your model:

PHP Code:
// Add this to your model.

/**
 * Prepare INSERT IGNORE SQL query
 *
 * @param Array $data Array in form of "Column" => "Value", ... 
 * @return Null
 */
protected 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 `titles` ('.implode(',',array_keys($_prepared)).') VALUES('.implode(',',array_values($_prepared)).');');


You may need to change it from protected to public if your not calling it from within.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
RE: use of Unique in mySQL field cases Error - by InsiteFX - 07-23-2020, 09:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB