php mysql stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prabapraba
    New Member
    • Jan 2008
    • 4

    #1

    php mysql stored procedure

    How to run the following stored procedure in php????





    CREATE PROCEDURE `mzappDelete`(t ableName 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
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Originally posted by prabapraba
    How to run the following stored procedure in php????





    CREATE PROCEDURE `mzappDelete`(t ableName 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($li nk, storedProcName( 'para')) ;
    // then work through the output of the SP.
    [/php]
    I hope this helps. I got my info from here

    Cheers
    nathj

    Comment

    • prabapraba
      New Member
      • Jan 2008
      • 4

      #3
      Thanks
      But we are using PEAR DB package ;

      How we call from pear

      Thanks Advance

      Comment

      • nathj
        Recognized Expert Contributor
        • May 2007
        • 937

        #4
        Originally posted by prabapraba
        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

        Comment

        Working...