I have a game engine that desperately needs upgraded from PHP 5 to PHP 7. I’m trying to tackle database functions for starters, but running into a lot of issues, and Google hasn’t been helpful, either.
The original code I need to convert is:
if (!isset($settings[$settingname]) && $value){
$sql = "INSERT INTO " . db_prefix("settings") . " (setting,value) VALUES (\"".addslashes($settingname)."\",\"".addslashes($value)."\")";
}else if (isset($settings[$settingname])) {
$sql = "UPDATE " . db_prefix("settings") . " SET value=\"".addslashes($value)."\" WHERE setting=\"".addslashes($settingname)."\"";
} else {
return false;
}
db_query($sql);
Here’s what I currently have:
$conn = mysqli_connect('localhost', 'username', 'password');
if (!isset($settings[$settingname]) && $value){
$sql = "INSERT INTO " . db_prefix("settings") . " (setting,value) VALUES (\"".addslashes($settingname)."\",\"".addslashes($value)."\")";
}else if (isset($settings[$settingname])) {
$sql = "UPDATE " . db_prefix("settings") . " SET value=\"".addslashes($value)."\" WHERE setting=\"".addslashes($settingname)."\"";
} else {
return false;
}
mysqli_query($conn, $sql);
The resulting error is:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given
So, I tried switching the values around, like this:
mysqli_query($conn, $sql);
And I get this error:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given
So I obviously have no idea what the mysqli_query() function wants. I appreciate any advice.