You should always sanitize the param that will be supplied into your SQL statement.
You may use PHP preg_replace to sanitize it.In addition, you may use RemoveXss global function to remove XSS attack from your param.
function UpdateModuleName($moduleID){
$param_moduleID = RemoveXss($moduleID); // remove the XSS if any; just in case
$param_moduleID = preg_replace('/[^a-zA-Z0-9]/', '', $param_moduleID); // only allow a-z, A-Z, 0-9 characters
return ExecuteScalar("SELECT Module FROM Updates_Modules WHERE id='".$param_moduleID."'");
}
Is it allowed to use prepared statements within ExecuteScalar, ExecuteRow, ExecuteQuery etc for sanitization?
// Prepare the SQL query
$query = "SELECT IP FROM Trusted_IPs WHERE IP = :userIp";
// Execute the query with parameter binding
$result = ExecuteQuery($query, ['userIp' => $userIp]);
If the SQL is simple as in your example, all are the same (in terms of SQL injection prevention). However, if the SQL is more complex, the first approach might lead to complex to maintain SQL queries, see Dynamic Parameters and Prepared Statements. The 2nd argument of ExecuteQuery() is not parameters, you need to handle the SQL as in the first approach, then the 2nd and 3rd approach are the same, only in different syntax.
The second argument of ExecuteQuery() is not parameters, see ExecuteQuery($sql [,$dbname]).If you want to use SQL paramters, you should use Conn() to get the connection and then execute $conn->executeQuery().