Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update btmysql.php #101

18 changes: 13 additions & 5 deletions src/classes/btmysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,25 @@ public function getParamTypes($arrValues) {
return $strParamTypes;
}

/**
* Binds variables to an SQL prepared statement as parameters. Similar to what PDO does with its 'WHERE field1 = ? AND field2 = ?' syntax. The params are inserted where the question marks are.
* @param object $objMySQLiStmt
* @param array $arrValues The values to bind to the statement, in order. For example, ['paramValue1', 'paramValue2']
* @return object $objMySQLiStmt
*/
public function bindParams($objMySQLiStmt, $arrValues) {
$returnVal = false;

// Get a string of letter codes corresponding to the types of each parameter. For example, if you have 3 parameters and they are all strings, the code is "sss". If you have 2 parameters and one is a double and one is an int, the code is "di".
$strParamTypes = $this->getParamTypes($arrValues);

$tmpParams = array_merge(array($strParamTypes), $arrValues);
RedDragonWebDesign marked this conversation as resolved.
Show resolved Hide resolved
$arrParams = array();
foreach ($tmpParams as $key => $value) {
$arrParams[$key] = &$tmpParams[$key];
// Create an array whose first value (spot 0) is the $strParamTypes, and all additional values are the param values, in order. For example, ['ss', 'paramValue1', 'paramValue2']
$params = array($strParamTypes);
foreach ($arrValues as $key => $value) {
$params[] = &$arrValues[$key];
}

if (!call_user_func_array(array($objMySQLiStmt, "bind_param"), $arrParams)) {
if (!call_user_func_array(array($objMySQLiStmt, "bind_param"), $params)) {
$returnVal = false;
echo $objMySQLiStmt->error;
echo "<br><br>";
Expand Down
Loading