0

Hi..
I want to call mysql Stored procedure with OUT parameter.
Its worked in phpamyadmin
But in php it returning empty result.
I have used the following php script.
Can anyone help me?

<?php
include("dbcon.php");
$countryname="india";

  $rs1 = mysql_query( 'CALL countCountry($countryname,@totalcount)' );
      $rs = mysql_query( 'SELECT @totalcount as totalcount' );
      $row = mysql_fetch_array($rs);

      var_dump($rs);

      while($row = mysql_fetch_array($rs))
      {

      echo $row['totalcount'];
      }
 ?>
4
Contributors
10
Replies
23
Views
2 Years
Discussion Span
Last Post by divyakrishnan
Featured Replies
  • 1

    Hmm.. Just a note... Are you trying to pass PHP variable into the call command -- `'CALL countCountry($countryname,@totalcount)'`? Read More

0

Have you tried just:

$rs = mysql_query( 'SELECT @totalcount' ) or die(mysql_error());

Also note that you are fetching twice. Once is enough.

Edited by pritaeas

0

Sorry ,its for debugging purpose I fetched twice.

I changed my script as follows

<?php
include("dbcon.php");
$countryname="india";

  $rs1 = mysql_query( 'CALL countCountry($countryname,@totalcount)' );
      //$rs = mysql_query( 'SELECT @totalcount as totalcount' );
      $rs = mysql_query( 'SELECT @totalcount' ) or die(mysql_error());
      while($row = mysql_fetch_array($rs))
      {

      echo $row['totalcount'];
      }
 ?>

Getting a notice like

Notice: Undefined index: totalcount in C:\xampp\htdocs\php\sp\example.php on line 9

0

Of course PDO is faster than MySQLi but i am not sure if we can use the same syntax for multiple database drivers!

0

@Harryjames: It's not about speed. It's just that the MySQL extension has a dubious history with stored procedures. Syntax is not an issue either, as he's just using MySQL anyway.

1

Hmm.. Just a note... Are you trying to pass PHP variable into the call command -- 'CALL countCountry($countryname,@totalcount)'?

0

Thank you very much
I have changed my script as

    <?php
    include("dbcon.php");
    $countryname="india";
    $rs1 = mysql_query( "CALL countCountry('$countryname', @totalcount)" );
    //$rs = mysql_query( 'SELECT @totalcount as totalcount' );
    $rs = mysql_query( 'SELECT @totalcount as totalcount' ) or die(mysql_error());
    while($row = mysql_fetch_array($rs))
    {
    echo $row['totalcount'];
    }
    ?>

Now its working.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.