converted from standard mysqli to mysqli prepared statements for security against sql injection

This commit is contained in:
2025-04-01 15:03:01 -06:00
parent e8ac27b5d5
commit cec9091ee0
7 changed files with 190 additions and 175 deletions
+1 -47
View File
@@ -22,54 +22,8 @@ if ($_SERVER['HTTP_HOST'] == 'localhost') {
define('DB', 'vintagecoding');
}
/*
* Handles any queries that should have only one row results.
*/
function query_one_result($query_stmt)
{
$conn = get_connection();
$results = mysqli_query($conn, $query_stmt);
mysqli_close($conn);
if (mysqli_num_rows($results) == 0 || mysqli_num_rows($results) > 1)
return null;
else
return mysqli_fetch_assoc($results);
}
function query_one_or_more_results($query_stmt)
{
$conn = get_connection();
$results = mysqli_query($conn, $query_stmt);
mysqli_close($conn);
if (mysqli_num_rows($results) == 0)
return null;
else
return $results;
}
/*
* Executes a statement. Type is typically either 0 or 1, where 0 is an INSERT or UPDATE,
* and 1 is DELETE. This is to determine whether a boolean value should be returned or
* the ID of the row(s).
*/
function exec_statement($stmt, $type)
{
$conn = get_connection();
$results = mysqli_query($conn, $stmt);
if ($type == 0)
$results = mysqli_insert_id($conn);
mysqli_close($conn);
return $results;
}
function get_connection()
{
// Connect to the DB
$conn = mysqli_connect(HOST, USER, PASS, DB);
$conn = new mysqli(HOST, USER, PASS, DB);
return $conn;
}