This is my 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
I am trying to get the return value with php:
$query=$this->db->query("select test(\"$begin\",\"$end\", \"$code\")")->result();
var_dump($query);
die;
The result is:
array(1) { [0]=> object(stdClass)#20 (1) { ["test("2007-01-01","2007-12-31", "1")"]=> string(7) "118" } }
My problem is that I want to get the value from stored procedure ("118") and I don't know how to change the object into a string.
Try this:
$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);
Perhaps will help..
If you need to send the object as text to somewhere else (database, Javascript code), you have a choice of serialize, json_encode, XML conversion, and many more, depending on your exact situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With