473,387 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. CREATE Procedure dbo.q_putaka
  2.  (
  3.   @key varchar(200),
  4.   @scope varchar(4) = null
  5.  
  6.  )
  7. As
  8.  if @scope ='1' 
  9.   execute ('select distinct author_name,book_id,remark,availability,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) ')
  10.  
  11.  else
  12.   if @scope='2'
  13.    execute ('select distinct author_name,book_id,remark,availability,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) ')
  14.  else
  15.  if @scope='12'
  16.   execute ('select distinct author_name,book_id,remark,availability,title  from v_pustaka where  '+@key +' and DOC_TYPE IN (SELECT NM_TYPE FROM TAKA.R_TYPEDOC) ')
  17.  
  18.  else
  19.   if @scope='123'
  20.    execute ('select distinct author_name, book_id,remark,availability,title  from v_pustaka where  '+@key +' and DOC_TYPE IN (SELECT NM_TYPE FROM TAKA.R_TYPEDOC )  union select convert(varchar,0),book_id,remark,availability,title from v_magazine where '+@key)
  21.    else
  22.       select distinct author_name, book_id,remark,availability,title  from v_pustaka 
  23.  
  24. GO
  25.  
n the problem is how to make the script php to call that store procedure?please help me n can you all tell me step by step cause i'm not familiar with script php using sql server database. thanks
Jan 21 '08 #1
4 8330
nathj
938 Expert 512MB
Have a look at this:
http://dev.mysql.com/doc/refman/5.0/en/call.html

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
Sep 1 '08 #2
Atli
5,058 Expert 4TB
Hi.

Take a look at the mssql_init and mssql_execute functions.
Sep 1 '08 #3
Try. mssql_bind() Example

[PHP]<?php

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

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

mssql_bind($sp, "@productname", stripslashes($newproduct), SQLVARCHAR, false, false, 150);
mssql_bind($sp, "@quantity", stripslashes($newquantity), SQLVARCHAR, false, false, 50);

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

?>
[/PHP]

See Also
mssql_bind() .....
mssql_execute()
mssql_free_statement()
Sep 5 '08 #4
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

Expand|Select|Wrap|Line Numbers
  1. DECLARE @TranID int 
  2. BEGIN TRANSACTION 
  3. EXEC sp_TransactionModify @TranID output, 1, 100.00, 0, 100.00, 123, 456, “2008-08-20”
  4. COMMIT
  5. SELECT @TranID as TransactionID
How can I do to make it work at php??

Thank you so much!!!!
Oct 1 '08 #5

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

Similar topics

11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
1
by: sollento | last post by:
Hi, How can I export SQL Server Stored Procedures to MS-Access? Cheers H
3
by: Borr | last post by:
Hi, I have an ASP .NET page, that runs client side timer that does something on the Server side and after that loads another page. So I have on client side something like : function...
3
by: lanem | last post by:
I want to call a server-side function, like a button's click event, from a client-side JavaScript function. How do I do that? Thanks.
12
by: karen | last post by:
Hi all : this is going to be a long post. So i apologize in advance :) i am converting a java program in VB right now. I am a java programmer by trade. so i am no expert in this department. I...
1
by: Radhakrishnans | last post by:
hai friends i am new to java and mysql.i have created stored procedures in mysql.Now i want to call that stored procedures in java.All works fine.but it show the following error. unreported...
2
by: Problematic coder | last post by:
I have a form based application that inputs values into various oracle tables, after it has done this I want to call a stored proceedure in Oracle which is already written to do more work on this...
1
by: Genken | last post by:
How would i convert or write a simple or complex access query to sql server stored procedures i will include my most complex query i hope somebody can help. Thankyou in advance. SELECT...
0
by: Ketki | last post by:
Hello Friends, To know how to call Server Side function from Client Side Code using PageMethods in ASP.NET AJAX, visit: http://www.dotnetcurry.com/ShowArticle.aspx?ID=109 Regards, Ketki
5
by: Simon | last post by:
I heard that we could do that by using AJAX. Could anybody share how to do it? Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.