converted from standard mysqli to mysqli prepared statements for security against sql injection
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user