How to call a MS SQL Server stored-procedure from PHP?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rinal86
    New Member
    • Jan 2008
    • 1

    How to call a MS SQL Server stored-procedure from PHP?

    hi i'm rizki. can you all help me? please

    i have a problem with script php to call procedure using sql server database this is the store procedure in sql server:
    [code=mysql]
    CREATE Procedure dbo.q_putaka
    (
    @key varchar(200),
    @scope varchar(4) = null

    )
    As
    if @scope ='1'
    execute ('select distinct author_name,boo k_id,remark,ava ilability,title from v_pustaka where '+@key +' and DOC_TYPE IN (SELECT NM_TYPE FROM TAKA.R_TYPEDOC WHERE CONVERT(INT,KD_ TYPE) <=3 AND CONVERT(INT,KD_ TYPE)>=1) ')

    else
    if @scope='2'
    execute ('select distinct author_name,boo k_id,remark,ava ilability,title from v_pustaka where '+@key +' and DOC_TYPE IN (SELECT NM_TYPE FROM TAKA.R_TYPEDOC WHERE CONVERT(INT,KD_ TYPE) <=6 AND CONVERT(INT,KD_ TYPE)>=4) ')
    else
    if @scope='12'
    execute ('select distinct author_name,boo k_id,remark,ava ilability,title from v_pustaka where '+@key +' and DOC_TYPE IN (SELECT NM_TYPE FROM TAKA.R_TYPEDOC) ')

    else
    if @scope='123'
    execute ('select distinct author_name, book_id,remark, availability,ti tle from v_pustaka where '+@key +' and DOC_TYPE IN (SELECT NM_TYPE FROM TAKA.R_TYPEDOC ) union select convert(varchar ,0),book_id,rem ark,availabilit y,title from v_magazine where '+@key)
    else
    select distinct author_name, book_id,remark, availability,ti tle from v_pustaka

    GO
    [/code]
    n the problem is how to make the script php to call that store procedure?pleas e help me n can you all tell me step by step cause i'm not familiar with script php using sql server database. thanks
    Last edited by Atli; Sep 1 '08, 11:49 PM. Reason: Added [code] tags and made the title a little clearer.
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Have a look at this:


    Personally I stay away from SP's as experience shows me that merging business layer and data layer causes problems further down the line. I would always keep code and data separate.

    Have you thought about PHP objects?

    nathj

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      Take a look at the mssql_init and mssql_execute functions.

      Comment

      • crocodilu2008
        New Member
        • Sep 2008
        • 9

        #4
        Try. mssql_bind() Example

        [PHP]<?php

        $cn = mssql_connect($ DBSERVER, $DBUSER, $DBPASS);
        mssql_select_db ($DB, $cn);

        $sp = mssql_init("WDu mpAdd"); // stored proc name

        mssql_bind($sp, "@productna me", stripslashes($n ewproduct), SQLVARCHAR, false, false, 150);
        mssql_bind($sp, "@quantity" , stripslashes($n ewquantity), SQLVARCHAR, false, false, 50);

        mssql_execute($ sp);
        mssql_close($cn );

        ?>
        [/PHP]

        See Also
        mssql_bind() .....
        mssql_execute()
        mssql_free_stat ement()

        Comment

        • ccassel82
          New Member
          • Oct 2008
          • 1

          #5
          Hi I have this SP to execute at php but I have no Idea how to do it

          this is the way I execute it on MSSQL

          [CODE=sql]DECLARE @TranID int
          BEGIN TRANSACTION
          EXEC sp_TransactionM odify @TranID output, 1, 100.00, 0, 100.00, 123, 456, “2008-08-20”
          COMMIT
          SELECT @TranID as TransactionID[/CODE]

          How can I do to make it work at php??

          Thank you so much!!!!
          Last edited by Atli; Oct 1 '08, 11:53 PM. Reason: Added [code] tags.

          Comment

          Working...