这是我的SP:
DELIMITER $$
CREATE DEFINER=FUNCTION `test`(p_begin varchar(10),p_end varchar(10),p_code varchar(2)) RETURNS varchar(10) CHARSET latin1
BEGIN
DECLARE V_ADA VARCHAR(8);
DECLARE V_LAST VARCHAR(8);
DECLARE V_NIK VARCHAR(8);
select NIK INTO V_NIK from absen where join_date >= p_begin and join_date<= p_end AND company_id=p_code ORDER BY NIK DESC LIMIT 1 ;
SET V_NIK=V_NIK+1;
return V_NIK;
END
我正在尝试使用php获取返回值:
$query=$this->db->query("select test(\"$begin\",\"$end\", \"$code\")")->result();
var_dump($query);
die;
结果是:
array(1) { [0]=> object(stdClass)#20 (1) { ["test("2007-01-01","2007-12-31", "1")"]=> string(7) "118" } }
我的问题是我想从存储过程(“ 118”)中获取值,而且我不知道如何将对象更改为字符串.
解决方法:
尝试这个:
$query=$this->db->query("select test(\"$begin\",\"$end\", \"$code\")")->result();
// Cast object to array (also you can try get_object_vars() to do that)
$query = (array)$query[0];
// Get the last value from array (it the only on so it is OK)
echo end($query);
也许会有所帮助.