Created
September 26, 2019 06:04
-
-
Save markggn/ba0361f202adce8a71e46640a2e29286 to your computer and use it in GitHub Desktop.
Replace into...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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