Member Avatar for Member #210412

here is my stored procedure

begin
select
indexes.IndexID,
languages.LanguageID,
languages.LanguageName,
indexes.OrderID,
indexes.IndexName
FROM
indexes, languages
where indexes.LanguageID = languages.LanguageID and languages.LanguageID = Language
order by indexes.OrderID asc;
end

here is my php code

<?php
$Server = "127.0.0.1";
$Port = ":"."3306";
$DataBase = "abc";
$UserName = "def";
$PassWord = "blabla";
$Flags = "MYSQL_CLIENT_SSL";
$Connection = mysql_connect($Server . $Port, $UserName, $PassWord, $Flags, 65536);
if(!$Connection)
{
    die("Could not connect to server : " . mysql_error());
}
else
{
    mysql_select_db($DataBase,$Connection) or die("Could not connect to database");
}

$TM = mysql_query("Call SP_Index($Language)",$Connection);
while($TM_W = mysql_fetch_array($TM))
{
	$i1++;
        print $TM_W[4];
}
?>

so far everything works fine after calling second procedure.
.... doesnt show up anything... i got empty array

<?php
$Cat = mysql_query("Call SP_Category($Language)",$Connection);
$Cat_N = mysql_num_rows($Cat);

while($Cat_W = mysql_fetch_array($Cat))
{
	$i3++;
        print $Cat_W[4]; 
}
?>

i closed and opened the connection and freed the previous array etc etc..
still nothing.. anyone has idea??

thanx in advance.

Dani AI

Generated

Short diagnosis: MySQL stored procedures can return one or more result sets plus a final status result; if the client (PHP) does not fetch / clear every result set produced by a CALL, subsequent queries on the same connection can return empty arrays or fail. Confirm the procedure returns rows by running the CALL directly in the MySQL client or phpMyAdmin and verify the procedure parameter usage (as hinted). (dev.mysql.com)

A reliable PHP pattern is to use mysqli and loop through all result sets, storing/freeing each before issuing another query. Example pattern:

$mysqli = new mysqli($host,$user,$pass,$db);
if ($mysqli->multi_query("CALL SP_Index('en')")) {
  do {
    if ($res = $mysqli->store_result()) {
      while ($row = $res->fetch_assoc()) { /* process row */ }
      $res->free();
    }
  } while ($mysqli->more_results() && $mysqli->next_result());
}

This consumes every result set (including the final status) so a second CALL will work reliably; the mysqli docs show this workflow. (php.net)

Notes and troubleshooting: using OUT variables is possible (as suggested) but the OUT/INOUT values themselves may appear as an extra single-row result set, so the same result-consumption rules apply. The old ext/mysql functions are deprecated/removed (migrate to mysqli or PDO); many “procedures won’t run” reports are actually result-handling issues rather than PHP bugs. For background on the removal of ext/mysql and the common “commands out of sync” symptom, see the PHP migration notes and community guidance. (dev.mysql.com)

Recommended Answers

All 10 Replies

Member Avatar for Member #210412

mysqli version.. doesnt work also... :(

<?php
$Server = "127.0.0.1";
$DataBase = "teknober";
$UserName = "root";
$PassWord = "19741968";
$Connection = mysqli_connect($Server, $UserName, $PassWord);
if(!$Connection)
{
    die("Could not connect to server : " . mysqli_error());
}
else
{
    mysqli_select_db($Connection,$DataBase) or die("Could not connect to database");
}
?>
<?php
print "Procedure #1<br>";

$TM = mysqli_query($Connection, "CALL mypro;");
while($TM_W = mysqli_fetch_array($TM))
{
	print $TM_W[2] . "<br>";
}

?>
<?php
print "<hr>";
print "Procedure #2<br>";
$TM = mysqli_autocommit($Connection,1);
$TM = mysqli_query($Connection, "select * from news;");
while($TM_W = mysqli_fetch_array($TM))
{
	print $TM_W[2] . "<br>";
}
?>

On your store procedure.
...
...
where indexes.LanguageID = languages.LanguageID and languages.LanguageID = Language
...
...

what is Language? Did you try with $Languaje (?)

ch.-

Member Avatar for Member #210412

language is the input parameter. i deleted it and still same. got error...

did you set an out parameter on the procedure?

Member Avatar for Member #210412

out parameter is not so important coz i need all values out. if i do something without using tables like:

declare in_x, in_y, out_z int;
select in_x * in_y = out_z;

select out_z;
end

i got a smiliar procedure to work on my server. i hope this helps.

here is the procedure:

CREATE PROCEDURE SP_Index (IN lang VARCHAR(255), OUT info BLOB) 
BEGIN
SELECT 
indexes.IndexID,
languages.LanguageID,
languages.LanguageName,
indexes.OrderID,
indexes.IndexName INTO info 
FROM indexes,languages 
WHERE indexes.LanguageID = languages.LanguageID AND languages.Language = lang 
ORDER BY indexes.OrderID ASC;
END

Here is the php:

<?php
$Server = "127.0.0.1";
$Port = ":"."3306";
$DataBase = "abc";
$UserName = "def";
$PassWord = "blabla";
$Flags = "MYSQL_CLIENT_SSL";
$Connection = mysql_connect($Server . $Port, $UserName, $PassWord, $Flags, 65536);
if(!$Connection)
{
    die("Could not connect to server : " . mysql_error());
}
else
{
    mysql_select_db($DataBase,$Connection) or die("Could not connect to database");
}

$TM = mysql_query("Call SP_Index($Language, @data)", $Connection);
$TM2 = mysql_query('SELECT @data');
while ($TM_W = mysql_fetch_array($TM2)) {

//DO WHAT YOU WANT

}
Member Avatar for Member #210412

Did you test this? It doesn't work, i got it work somehow but.. when i call the second procedure..

still error.. no output

yes i did test it and it worked for me. did you set up your other procedure the same way? i have looked into procedures before but i have never really used them. i am going off basic knowledge and the mysql manual. i am just as lost as you are to why this is not working.

Member Avatar for Member #210412

i m get more used to mssql procedures... i think i need to write kinda php module to execute multi stored procedures. thanks anyways

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.