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

Here is the whole class for it, I had to track it down. Just make the changes that you need.

PHP Code:
<?php
class Users extends Model {

    public function __construct() {
        parent::__construct();
    }

    public function test() {
        $_data = array(
            'field1' => 'value1',
            'field2' => 'vallue2',
            'field3' => 'value3'
        );

        $this->insert_ignore($_data);
    }

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



And here is another one I found:

PHP Code:
public function insertIgnore(array $data)
{
    $sql $this->db->insert_string('titles'$data);
    $sql str_replace('INSERT INTO''INSERT IGNORE INTO'$sql);

    $this->db->query($sql);

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-25-2020, 11:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB