Skip to content

Instantly share code, notes, and snippets.

@markggn
Created September 26, 2019 06:04
Show Gist options
  • Save markggn/ba0361f202adce8a71e46640a2e29286 to your computer and use it in GitHub Desktop.
Save markggn/ba0361f202adce8a71e46640a2e29286 to your computer and use it in GitHub Desktop.
Replace into...
public function replace($table, $data){
$q="REPLACE INTO `$table` ";
$v=''; $n='';
foreach($data as $key=>$val){
$n.="`$key`, ";
if(strtolower($val)=='null') $v.="NULL, ";
elseif(strtolower($val)=='now()') $v.="NOW(), ";
else $v.= "'".$this->escape($val)."', ";
}
$q .= "(". rtrim($n, ', ') .") VALUES (". rtrim($v, ', ') .");";
if($this->query($q)){
return mysqli_insert_id($this->link_id);
} else{
return false;
}
}#-#replace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment