Created
December 5, 2018 21:50
-
-
Save thewasta/f7b4c30035330cb792217ebb33b0519e to your computer and use it in GitHub Desktop.
Simple function to insert DB
This file contains hidden or 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
<?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