Hello this is my first posting here, so if I'm doing something wrong in my question and I will try to fix it.
So anyway. I'm trying to and some security to a database interface class and its functions. The error I am getting is: "Warning: mysqli_stmt_bind_param(): Invalid type or no types specified in "blah blah" line 46 which I will mark below
public function RunSql($Sql, $BindVars) {
$con = DataBase::ConDataBase(); // setting up connection
$type = DataBase::MakeTypes($BindVars);// make type string to send to bind_param.
$result = DataBase::ReturnData($Sql, $BindVars, $type);
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
$_SESSION['connection'] = $con;
return $result;
}
This is my second step it sends the array and Sql to the DB using mysqli functions
public function ReturnData($Sql, $BindVars, $type) {
$con = DataBase::ConDataBase();// connecting to DB again
$stmt = $con->prepare($Sql);
$sql_stmt = mysqli_prepare($con, $Sql);
These two are what I have been trying to learn about, they are supposed to do the same thing but I cant seem to get either working.
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($sql_stmt, $type), DataBase::refValues($BindVars)));
//call_user_func_array(array($sql_stmt, $type), DataBase::refValues($BindVars));
these are the erroring lines. and I am lost .
mysqli_stmt_execute($sql_stmt);
$stmt->store_result();
$result = $stmt->get_result();
return $result;
}
This takes and iterates though the Array of values to use in the Sql and builds the $type string that bind_param needs.
public function MakeTypes($BindVars) {
$type = "";
foreach ($BindVars as $value) {
$type .= substr(gettype($value), 0, 1);
}
//echo $type;
}
I'm not sure what this does it came from answer on here... and I cant seem to find it right now
public function refValues($arr) {
$refs = array();
foreach ($arr as $key => $value) {
$refs[$key] = &$arr[$key];
}
return $refs;
}
I am sorry for the long flood of code but I think might all be relevant to whom ever can help me get this working.
Best of luck and thank you for your time.