For some unknown reasons, you might get error message when you are calling LoadProfileFromDatabase() and SaveProfileToDatabase() functions. These both functions are located in your generated phpfn9.php file. The following customization below will prevent that error message by improving some code in those both functions. We will customize the template file for this purpose, and not modify any generated code, so we can use the template for other future projects. Curious?
[hidepost]
-
Open your \Script\phpfn.php file, and find this code:
function LoadProfileFromDatabase($usr) { global $conn, $<!--##=sSecTblVar##-->; if ($usr == "" || $usr == EW_ADMIN_USER_NAME) // Ignore hard code admin return FALSE; $sFilter = str_replace("%u", ew_AdjustSql($usr), EW_USER_NAME_FILTER); // Get SQL from GetSQL function in <UserTable> class, <UserTable>info.php $sSql = $<!--##=sSecTblVar##-->->GetSQL($sFilter, ""); $rswrk = $conn->Execute($sSql); if ($rswrk && !$rswrk->EOF) { $this->LoadProfile($rswrk->fields(EW_USER_PROFILE_FIELD_NAME)); $rswrk->Close(); return TRUE; } return FALSE; }then replace it with the following code:
function LoadProfileFromDatabase($usr) { global $conn, $<!--##=sSecTblVar##-->; if ($usr == "" || $usr == EW_ADMIN_USER_NAME) // Ignore hard code admin return FALSE; $sFilter = str_replace("%u", ew_AdjustSql($usr), EW_USER_NAME_FILTER); // Get SQL from GetSQL function in <UserTable> class, <UserTable>info.php // $sSql = $<!--##=sSecTblVar##-->->GetSQL($sFilter, ""); $sSql = "SELECT " . EW_USER_PROFILE_FIELD_NAME . " FROM " . EW_USER_TABLE . " WHERE " . $sFilter; $rswrk = $conn->Execute($sSql); if ($rswrk && !$rswrk->EOF) { $this->LoadProfile($rswrk->fields(EW_USER_PROFILE_FIELD_NAME)); $rswrk->Close(); return TRUE; } return FALSE; } -
Still in that \Script\phpfn.php file, find again this code:
function SaveProfileToDatabase($usr) { global $conn, $<!--##=sSecTblVar##-->; if ($usr == "" || $usr == EW_ADMIN_USER_NAME) // Ignore hard code admin return FALSE; $sFilter = str_replace("%u", ew_AdjustSql($usr), EW_USER_NAME_FILTER); $sSql = "UPDATE " . ew_QuotedName($<!--##=sSecTblVar##-->->TableName) . " SET " . ew_QuotedName(EW_USER_PROFILE_FIELD_NAME) . "='" . ew_AdjustSql($this->ProfileToString()) . "' WHERE " . $sFilter; $conn->Execute($sSql); $_SESSION[EW_SESSION_USER_PROFILE] = $this->ProfileToString(); }then replace it with the following code:
function SaveProfileToDatabase($usr) { global $conn, $<!--##=sSecTblVar##-->; if ($usr == "" || $usr == EW_ADMIN_USER_NAME) // Ignore hard code admin return FALSE; $sFilter = str_replace("%u", ew_AdjustSql($usr), EW_USER_NAME_FILTER); //$sSql = "UPDATE " . ew_QuotedName($<!--##=sSecTblVar##-->->TableName) . $sSql = "UPDATE " . EW_USER_TABLE . " SET " . ew_QuotedName(EW_USER_PROFILE_FIELD_NAME) . "='" . ew_AdjustSql($this->ProfileToString()) . "' WHERE " . $sFilter; $conn->Execute($sSql); $_SESSION[EW_SESSION_USER_PROFILE] = $this->ProfileToString(); } - Did you see the difference now? 🙂
- Finally, re-generate your phpfn9.php file using PHPMaker.
[/hidepost]
[…] How to Improve LoadProfileFromDatabase() and SaveProfileToDatabase() Functions in PHPMaker Template […]