By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,731 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,731 IT Pros & Developers. It's quick & easy.

php mysql stored procedure

P: 4
How to run the following stored procedure in php????





CREATE PROCEDURE `mzappDelete`(tableName char(100), fieldName char(100), fieldValue int(10), out flag char(100))
BEGIN

SET @s= CONCAT('select count(*) from ',tableName,' where ',fieldName,' = ',fieldValue);
prepare stmt from @s;
execute stmt;

END

Thanks advance
Jan 8 '08 #1
Share this Question
Share on Google+
3 Replies


nathj
Expert 100+
P: 938
How to run the following stored procedure in php????





CREATE PROCEDURE `mzappDelete`(tableName char(100), fieldName char(100), fieldValue int(10), out flag char(100))
BEGIN

SET @s= CONCAT('select count(*) from ',tableName,' where ',fieldName,' = ',fieldValue);
prepare stmt from @s;
execute stmt;

END

Thanks advance
Hi,

I've never done this as I don't like the idea of code in a database - it's not real OO and it's certainly not a propoper tiered structure. That said I think that you just call it as the second parameter of a normal query:
[php]
// assuming the link has been stored in $link)
$result = mysql_query($link, storedProcName('para')) ;
// then work through the output of the SP.
[/php]
I hope this helps. I got my info from here

Cheers
nathj
Jan 8 '08 #2

P: 4
Thanks
But we are using PEAR DB package ;

How we call from pear

Thanks Advance
Jan 9 '08 #3

nathj
Expert 100+
P: 938
Thanks
But we are using PEAR DB package ;

How we call from pear

Thanks Advance
Unfortunately I have no idea how to do this as I have never used PEAR.

Is there any reason why the procedure hcan't be moved out of the database? Yu could have it ona PHP class or even just in a PHP file and then call it as it required in a normal PHP fashion.

I know SP's can be a littel faster but in terms of re-usability, maintenance and future development they're a pain, so perhaps the trade-off is worht it.

Other than that I'm out of helpful suggestions.

Cheers
nathj
Jan 9 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.