this is my code

$query="call call_history('','$real_sdate','$real_edate','$level','$userid',@_count,'0','10')";

 //Listing the result
 $rs = mysqli_query($mysqli,$query);
 
$rs = mysqli_query($mysqli,"SELECT @_count");
while($row = mysqli_fetch_assoc($rs))
{
print_r $row;
}

always i get blank result or error mysqli_fetch_assoc() expects parameter 1 to be mysqli_result

i want to do it with procedural mysqli.. not with oop mysqli..!!

Can anybody help.?

Member Avatar for nileshgr

what's call_history in your query ? can please post its code ?

as u clearly see that i m using call before call_history.. this show that its a store procedure..!!! and store procedure is working fine...

this store procedure has a out parameter..!!!
i just want to store that out parameter in an variable in php..!!

kindly tell me how to get out parameter in php

strange nobody knows how to get out parameter in php.. :O

i already tried tht link... but fail..!!
have u ever personally use that link..? :O

Member Avatar for nileshgr

here you go dude. got this result after a lot of google work.

i create this procedure -

DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`p`$$
CREATE PROCEDURE `test`.`p` (out n INT)
BEGIN

SET n := 252;

END$$

DELIMITER ;

Now if i pass a param to the proccy, i should get 252 coz its out param.

<?php

$l = mysqli_connect('localhost', 'root', 'PAsSword', 'test');

$res = mysqli_query($l,"call p(@a);");

$res = mysqli_query($l, "select @a");

while($r = mysqli_fetch_array($res)) {
	
	var_dump($r);

}

and here's the output -

array(2) {
  [0]=>
  string(3) "252"
  ["@a"]=>
  string(3) "252"
}

Little change in your procedure -

DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`p`$$
CREATE PROCEDURE `p`(sid int,out n INT) # sid is IN parameter
BEGIN
select * from student where id = sid;  # test query
SET n := 252;
END$$

DELIMITER ;

PHP Code to get in as well as out parameter

<?php

$l = mysqli_connect('localhost', 'root', 'PAsSword', 'test');

$res = mysqli_query($l,"call p('1',@a);"); //1 is parameter

$res = mysqli_query($l, "select @a");

while($r = mysqli_fetch_array($res)) {
	
	var_dump($r);

}

i got the error..!!!

Commands out of sync; you can't run this command now

after little google i came our error..!!!
Thanks a lot..!!
:)

Member Avatar for nileshgr

What's the fix you got ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.