Skip to content

Instantly share code, notes, and snippets.

@thewasta
Created December 5, 2018 21:50
Show Gist options
  • Save thewasta/f7b4c30035330cb792217ebb33b0519e to your computer and use it in GitHub Desktop.
Save thewasta/f7b4c30035330cb792217ebb33b0519e to your computer and use it in GitHub Desktop.
Simple function to insert DB
<?php
/**
* Created by Schenier Aldair Lopez
* Date: 05/12/18
* Time: 21:32
*
*/
//insertSQL('users',['user_name'=>$_POST['user']]);
insertSQL('users',['user_name'=>'userName','user_pass'=>'afasdasd']);
function insertSQL($table,$datas){
$values = array_values($datas);
$value = [];
foreach ($values as $key) {
$value[]="\"".$key."\"";
}
$values = implode(",",$value);
$column = [];
foreach ($datas as $key => $value){
$column[]=$key;
}
$nameColumn=implode(",",$column);
$query = "INSERT INTO $table ($nameColumn) VALUES ($values)";
echo $query;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment