forked from egbot/Symbiota
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Backward Compatiblity Issue involving mysqli_execute_query (#1682)
* Adds util function to make use of mysqli_execute_query for older versions of php # Summary `mysqli_execute_query` or `$mysqli->execute_query` function is an 8.2 only function provided by mysqli which could break portals that cannot upgrade to 8.2 from 8 or are running 7.3. Solution is to make a util function with the same api as mysqli_execute_query but will use the php version to decide wether to use mysqli_execute_query or normal statement binding. * removing comment left over from prototyping
- Loading branch information
Showing
5 changed files
with
75 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
class SymbUtil { | ||
/* | ||
* This function is a wrapper for mysqli_execute_query. Not all Symbiota portals can update version so this an effort to fix backward compat issues | ||
* | ||
* @param mysqli $conn | ||
* @param string $sql | ||
* @param string $params | ||
*/ | ||
static function execute_query(mysqli $conn, string $sql, array $params): mysqli_result | bool { | ||
//This is supported from 4 to 8 | ||
$version = phpversion(); | ||
[$major, $minor, $patch] = explode('.', $version); | ||
|
||
if($major >= 8 && $minor >= 2) { | ||
return mysqli_execute_query($conn, $sql, $params); | ||
} else { | ||
$bind_params_str = ''; | ||
foreach($params as $param) { | ||
//Could just bind string instead? | ||
if(gettype($param) === 'string') { | ||
$bind_params_str .= 's'; | ||
} else { | ||
$bind_params_str .= 'i'; | ||
} | ||
} | ||
$stmt = $conn->prepare($sql); | ||
$stmt->bind_param($bind_params_str,...$params); | ||
$stmt->execute(); | ||
return $stmt->get_result(); | ||
} | ||
} | ||
} | ||
?> |