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

14 changes: 13 additions & 1 deletion src/classes/btmysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,34 @@ 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
// Create an array whose first value (spot 0) is the $strParamTypes, and all additional values are the $arrValues. For example, ['ss', 'paramValue1', 'paramValue2']
$tmpParams = array_merge(array($strParamTypes), array_values($arrValues));
// TODO: can we delete these 6 lines below? $tmpParams above might provide the format we need without the foreach loop. maybe unit test before deleting.
$arrParams = array();
foreach ($tmpParams as $key => $value) {
$arrParams[$key] = &$tmpParams[$key];
}

if (!call_user_func_array(array($objMySQLiStmt, "bind_param"), $arrParams)) {
// TODO: can probably get rid of $returnVal and just return the appropriate values
$returnVal = false;
echo $objMySQLiStmt->error;
echo "<br><br>";
$this->displayError("btmysql.php - bindParams");
} else {
// TODO: guard clause instead of else
$returnVal = $objMySQLiStmt;
}

Expand Down
Loading