php - Returning many columns in a function call -


although works fine, i want learn (i read on web , looked examples couldn't find anything) if ask below possible. can see in function, concatenate 3 columns return 1 single string , explode in php code use them.

can return 3 columns individually in 1 go without using concat_ws() , not use explode in php?

thanks

my mysql function:

drop function if exists function_institute_university;  delimiter $$  create function function_institute_university (in_partnership_id integer(11)) returns varchar(250) deterministic  begin     declare inscode_uniid_unicode varchar(250);      select         concat_ws('~',             upper(institute.code),             university.id,             upper(university.univacronym)         ) inscode_uniid_unicode     partnership     left join institute on institute.id = partnership.iid     left join university on university.id = partnership.uid             partnership.id = in_partnership_id ,         partnership.active = '1'       limit 1;      return inscode_uniid_unicode; end$$  delimiter ; 

my php code:

$sql = "select function_institute_university(15)"; $runsql = mysql_query($sql);  if(@mysql_num_rows($runsql) == 1) {    $newarray = mysql_fetch_array($runsql);    list($institutecode, $universityid, $universitycode) = explode('~', $newarray[0]); } 

update: after second see you're using function(completely overlooked) returns 1 value , can change procedure instead?

sql:

drop procedure if exists procedure_institute_university;  delimiter $$  create procedure procedure_institute_university (in_partnership_id integer(11)) begin     select         upper(institute.code) `institiute_code`,         university.id `university_id`,         upper(university.univacronym) `university_acronym`     partnership     left join institute on institute.id = partnership.iid     left join university on university.id = partnership.uid             partnership.id = in_partnership_id ,         partnership.active = '1'       limit 1; end$$ 

php:

$sql = "call procedure_institute_university(15)"; $runsql = mysql_query($sql);  if(@mysql_num_rows($runsql) == 1) {    $newarray = mysql_fetch_array($runsql);    list($institutecode, $universityid, $universitycode) = $newarray[0]['institute_code'], $newarray[0]['university_id'], $newarray[0]['university_acronym']; } 

added alias can retrieved. use mysql_fetch_assoc(http://php.net/manual/en/function.mysql-fetch-assoc.php) instead associative array. please read warning message in page when read docs.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -