• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 837
  • Last Modified:

I get error "PROCEDURE xxx can't return a result set in the given context" when I call php script

I got php script to get results from MySql prosedure (view). When i call prosedure from MySql server it's working, but PHP script give me error:  "PROCEDURE xxx can't return a result set in the given context". PHP script working with select queries (view). When prosedure return that same view to the script it's not working.

What's wrong with the PHP-script. Any comments would be great.

Mircci

Prosedure:
CREATE DEFINER=`kulmakonditoria`@`%` PROCEDURE `Kirjaudu`(Tunnus VARCHAR(50),Salasana VARCHAR(50))
BEGIN
 
SELECT Nimi FROM Tekijat
WHERE Tekijat.Tunnus = Tunnus AND Tekijat.Salasana=Salasana;
 
END
_____________________________________________________
PHP::
<?php
header('Content-type: application/octet-stream');
$runSQL = true;	
error_reporting(0);
$value="<flashsql>";
 
if($runSQL){
	if (!mysql_connect($_POST['host'], $_POST['uname'], $_POST['pword'])) {
		//Could not connect to database
		$value.=" <database_connection>0</database_connection>\n";
		$value.=" <error>".utf8_encode(mysql_error())." </error>\n";
	}else{
		$value.=" <database_connection>1</database_connection>\n";
		if(!mysql_select_db($_POST['dat'])){
			//Connected to database but cannot select database
			$value.=" <database_selection>0</database_selection>\n";
			$value.=" <error>".utf8_encode(mysql_error())." </error>\n";
		}else{
			//Connected to and selected database
			$value.=" <database_selection>1</database_selection>\n";
			$qry_val = iconv("UTF-8", "ISO-8859-1", stripcslashes($_POST['query']));
			if(!$result = mysql_query($qry_val)){
				$value.=" <sql>0</sql>\n"; //sql failed to run
				$value.=" <error>".utf8_encode(mysql_error())." </error>\n";
			}else{
				$value.=" <sql>1</sql>\n"; //sql ran well
				$value.=" <results>\n";
					$num_cols = mysql_num_fields($result);
					$count = 1;
					while ($row = mysql_fetch_row($result)){
						$value.="<record>\n<count>".$count."</count>\n";
						for($i=0; $i<$num_cols; $i++){
							$vals = "<".mysql_field_name($result,$i)."> <![CDATA[".$row[$i]."]]></".mysql_field_name($result,$i).">";
							$value.=$vals;
						}
						$value.="</record>";
						$count++;
					}
				
				$value.=" </results>\n";
			}
		}
	}
}
$value.="</flashsql>";
//print $value;
print gzcompress($value);
?>

Open in new window

0
Mircci
Asked:
Mircci
  • 2
  • 2
1 Solution
 
NoiSCommented:
Are you trying to execute an Stored Procedure?
The mysql extension don't work with Stored Procedure;

Try changing to mysqli, PDO, ADODB, etc;

0
 
MircciAuthor Commented:
I'm calling procedure (CALL kulmakonditoria.Kirjaudu('Mirka','joku')) from Flex (as3) application. PHP Script working with that, only results from procedure (view) it's not working.
0
 
NoiSCommented:
So.. the mysql extension don't have the ability to retrieve data from cursors.

You must use another extensions.
See in your phpinfo(); what extension you have. If you have mysqli use it. Is almos the same code thar mysql extension.
0
 
MircciAuthor Commented:
Two hours and I got it, heh. Thank you very much!
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now