How do I use a MySQL user-defined function from within PHP? -


spent several hours searching answer without success. i've written user-defined function in mysql passed identifier uses retrieve various pieces of data, concatenate 1 string , return it. want call function php page , output result.

unsuccessful attempts include:

1. $result = mysql_query("select functionname($id)");   2. $sql = "select functionname($id)";    $result = mysql_query($sql, $link);  3. functionname($id)  

any ideas?

1 , 2 close, $result not going contain result of function call. rather, going contain result cookie query. can use cookie actual data, mysql_fetch_row(). function call returns value select statement, same "select 42" or "select mytable". result use same mechanism other sql query returns results; is, use cookie , call mysql_fetch_row(). final code this:

$result = mysql_query("select functionname($id)"); $row = mysql_fetch_row($result, $link); $returnvalue = $row[0]; 

note don't want interpolating variables directly sql string (that can vector attacks). assume, however, code example purposes.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -