error while calling stored procedure from php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shaam
Forum Newbie
Posts: 20
Joined: Tue Jun 23, 2009 6:36 am

error while calling stored procedure from php

Post 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
Last edited by Weirdan on Thu Jun 25, 2009 12:21 pm, edited 1 time in total.
Reason: added [code] tags
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: error while calling stored procedure from php

Post by Christopher »

I think you may need quotes:

Code: Select all

$res = $mysqli->multi_query( "CALL p1('$vTableName');" );
 
(#10850)
shaam
Forum Newbie
Posts: 20
Joined: Tue Jun 23, 2009 6:36 am

Re: error while calling stored procedure from php

Post 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
Post Reply