Is there a way to call a MySQL stored function (not procedure) in Zend Framework? Or work around the framework to use unfiltered PHP code?
In a 'pure' php application, the following code works - using the mysqli db connection (not mysql). However in Zend framework, this code will not cause an application error but will also not bind the result to the php variable.
If you use a Zend_Db adapter, there is no way I can find to bind the result of the function to a variable (and thus get the answer - there is no Zend_Db method equivalent to 'bind_result').
I have looked at previous questions but they focus on stored procedures (e.g. How can I use a stored procedure in a MySql database with Zend Framework? ).
Thanks.
UPDATE: Since writing, I've discovered that this works fine with MYSQL on MAMP, but not with MYSQL on Zend Server CE on Mac.
MySQL stored function:
CREATE FUNCTION GetUserAccountType(
inUsername VARCHAR(50)
) RETURNS INT(3)
BEGIN
SELECT AccountType_i INTO @retVal FROM UserTable WHERE Username_vc = inUsername;
RETURN @retVal;
END;
GO
Php code calling the MySQL function:
// open mysqli connection with db
$my_db = new mysqli($db_hostname, $db_username, $db_password, $db_database);
// Prepare MySQL function ($userName is a string)
$stmt=$my_db->prepare("SELECT GetUserAccountType(?)") or die($my_db->error);
$stmt->bind_param('s', $userName) or die($stmt->error);
$stmt->execute() or die($stmt->error);
$stmt->bind_result($result);
$stmt->fetch();
// (in php the $result variable is now set as the result of the MySQL function, @retVal.
// In Zend framework, the $result variable is set to FALSE)
return $result;