Click here to Skip to main content
15,911,890 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i uesd query for Call procedure
i want to use prepare for do this.
how should i do this?

with query :

PHP
if($con = mysqli_connect("localhost", "root", $pass))
		{
			mysqli_select_db($con, "toggery");
			mysqli_set_charset($con, "utf8");
			$p = $con->query("CALL Select_State()");
			echo"<select name='sel1'>";
		while($row = mysqli_fetch_array($p, MYSQLI_ASSOC))
		{
			echo"<option value='$row[StateID]'>$row[Name]</option>";
		}		
			echo"</select>";	
		if(isset($_POST['sbm']))
		{
			echo $s = $_POST['sel1'];
		}
		}		
		else
		{
			echo 'db error!';
		}

with prepare :
PHP
if($con = mysqli_connect("localhost", "root", $pass))
		{
			mysqli_select_db($con, "toggery");
			mysqli_set_charset($con, "utf8");
			$p = $con->prepare("CALL Select_State()");
			$p->execute();
			echo"<select name='sel1'>";
		while($row = mysqli_fetch_array($p, MYSQLI_ASSOC))
		{
			echo"<option value='$row[StateID]'>$row[Name]</option>";
		}		
			echo"</select>";	
		if(isset($_POST['sbm']))
		{
			echo $s = $_POST['sel1'];
		}
		}		
		else
		{
			echo 'db error!';
		}


What I have tried:

not thing happened!
no error!
but with query it works true!
Posted
Updated 8-Sep-16 12:46pm
v5
Comments
David_Wimbley 7-Sep-16 19:23pm    
Your issue isn't clear. You posted the same code snippet twice. Are you saying your using a stored procedure (the code you posted) but want to use a prepared select statement?

Well if the issue is with your prepared select statement, you should post that PHP code instead of the one that works.

If i misunderstood this issue, please feel free to clarify.
ZurdoDev 7-Sep-16 21:22pm    
I do not understand what you are asking us.
saeed rajabi 8-Sep-16 5:33am    
i cant get answer from prepare function but i can get from query!

1 solution

Try using PHP: mysqli_stmt::get_result[^] after executing the statement. There's a quite good example you can modify at PHP: Stored Procedures - Manual[^]. See Example #4.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900