Page 1 of 1

error while calling stored procedure from php

Posted: Thu Jun 25, 2009 3:35 am
by shaam
Hi guys,im calling a simple stored procedure from php passing parameter for table name,but its not working showing nothing,

stored procedure:

Code: Select all

 
DROP PROCEDURE `p1`//
CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`(IN `strTable` VARCHAR(50))
SELECT * FROM strTable
 
php code:

Code: Select all

 
<?
$mysqli = new mysqli( "localhost", "root", "", "test2" );
 $vTableName="student";
$res = $mysqli->multi_query( "CALL p1($vTableName);" );
 
 
if( $res )
{
echo "if"; 
$j=0;
if ($result = $mysqli->store_result()) { 
while( $row = $result->fetch_row() ) {
echo "
";
foreach( $row as $cell )
{
echo $cell. "<===|====>";
++$j;
}
echo "
 
";
}
$result->close(); 
}
 
}
$mysqli->close();
 
?>
 
can anyone help me ??

Thanks in advance

Re: error while calling stored procedure from php

Posted: Thu Jun 25, 2009 11:42 am
by Christopher
I think you may need quotes:

Code: Select all

$res = $mysqli->multi_query( "CALL p1('$vTableName');" );
 

Re: error while calling stored procedure from php

Posted: Fri Jun 26, 2009 8:53 am
by shaam
Thanks arborint for your reply,
The quotes are not the issue,i check it by using quotes but does't work,
the issue is in stored procedure it don't accepts the table name as variable it treats it as a literal,i.e
DROP PROCEDURE `p1`//
CREATE DEFINER=`root`@`localhost` PROCEDURE `p1`(IN `strTable` VARCHAR(50))
SELECT * FROM strTable

it does't accept 'strTable' as a variable it treats it as a table name,its working if we passed it in where clause but not working in from clause.

any idea ??

Thanks in advance