This code inserts data into the database successfully. I havewas concerned about whether it is a considered good practise to go about inserting data into the following PHP function:database in this way. Is there something I am not considering?
function insertTest(){
global $db;
$field_names = array("id", "first_name", "last_name", "email");
$alias = array(":id", ":fn", ":ln", ":em");
$assignment = array(":id" => "2k39dk38dk2k39dk38dk2k39dk38dk2k39dk38dk",
":fn" => "Chris",
":ln" => "Moore",
":em" => "[email protected]");
$array = array();
$array['table'] = 'users';
$array['field_names'] = $field_names;
$array['alias'] = $alias;
$array['assignment'] = $assignment;
$q = "INSERT INTO `%s` (%s) VALUES (%s)";
$q = sprintf($q, $array['table'], implode(", ",$array['field_names']), implode(", ",$array['alias']));
$q = $db->prepare($q);
$r = $q->execute($assignment);
print_r($r);
return $r;
}
The code inserts data into the database successfully. I was concerned about whether it is a considered good practise to go about inserting data into the database in this way. Is there something I am not considering? I'm a beginner at PDO.
Thanks.