Skip to content

Commit

Permalink
Add insertIgnore method to allow insert of override unique keys
Browse files Browse the repository at this point in the history
  • Loading branch information
adambinnersley authored Jan 10, 2025
1 parent d503429 commit ac44c79
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ public function insert($table, $records)
return $this->numRows() ? true : false;
}

/**
* Inserts into database using the prepared PDO statements but ignore and overides existing unique keys
* @param string $table This should be the table you wish to insert the values into
* @param array $records This should be the field names and values in the format of array('fieldname' => 'value', 'fieldname2' => 'value2', etc.)
* @return boolean If data is inserted returns true else returns false
*/
public function insertIgnore($table, $records)
{
unset($this->prepare);

$this->sql = sprintf("INSERT IGNORE INTO `%s` (%s) VALUES (%s);", SafeString::makeSafe($table), $this->fields($records, true), implode(', ', $this->prepare));
$this->executeQuery(false);
return $this->numRows() ? true : false;
}

/**
* Updates values in a database using the provide variables
* @param string $table This should be the table you wish to update the values for
Expand Down

0 comments on commit ac44c79

Please sign in to comment.