Hi, I'm using SQLSRV driver for my php to communicate with SQL DBMS, and I found some problem that I cannot resolve (I'm pretty new in this)
my SP looks like this:
USE [Warehouse]
GO
/****** Object: StoredProcedure [dbo].[AGCT_InsertOrder] Script Date: 30.10.2012. 14:10:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AGCT_InsertOrder](
@User AS [int] ,
@forwarder AS [nchar](4),
@liner AS [nvarchar](100),
@booking AS [nvarchar](30),
@category AS [nvarchar](10),
@customs_id AS [nvarchar](50),
@customs_date AS [smalldatetime],
@type_of_job AS [nchar](10),
@need_weighing AS [bit],
@need_sampling AS [bit],
@username AS [nvarchar](20),
@good_card AS [nchar](8) = NULL
)
AS
DECLARE @ret as varChar(6)
DECLARE @order as nchar(6)
SELECT @order = dbo.AGCT_GetOrderNumber()
IF @order = '??????'
RETURN ''
if @good_card IS NULL
SELECT @good_card = dbo.AGCT_GetCardNumber()
IF @good_card is null
return ''
BEGIN TRANSACTION
BEGIN TRY
UPDATE dbo.GoodsCard set category = @category,goods_owner = @liner,forwarder = @forwarder ,[status] = 1
where card_id = @good_card
INSERT dbo.Orders SELECT
@order,
@User ,
@forwarder,
@liner,
@booking,
@category,
@customs_id,
@customs_date,
@type_of_job,
@need_weighing,
@need_sampling,
1,
GETDATE(),
@username,
GETDATE(),
null,
null,
@good_card
SET @ret = @order
END TRY
BEGIN CATCH
select @@ERROR
SET @ret = ''
END CATCH
IF @ret <> ''
begin
COMMIT TRANSACTION
return @ret
end
ELSE
ROLLBACK TRANSACTION
the goal is to get "return @ret" using php.
I found some interesting topics that are similar but it doesn't work for me:
This is my php code that I used to try to get ret value from SP.
<?php
session_start();
include('dbconn.php');
//if ($_SESSION['user']['password']) {
if (isset($_POST['needweigh']) && isset($_POST['needsampl'])) {
$needweight = 1;
$needsampl = 1;
} else if (isset($_POST['needweigh'])) {
$needweight = 1;
$needsampl = 0;
} else if (isset($_POST['needsampl'])) {
$needsampl = 1;
$needweight = 0;
} else {
$needweight = 0;
$needsampl = 0;
}
$dat = strtotime(str_replace('/', '-', $_POST['customsdate']));
$date = date('Y-m-d H:i:s', $dat);
if ($_POST['select_card'] == "") {
$val = array(null);
} else {
$val = array($_POST['select_card'],SQLSRV_PARAM_IN);
}
// var_dump($id, $fwd, $lin, $book, $categ, $custmi, $custmd, $typ, $needw, $needs, $usrn, $val);
$sq = "{call AGCT_InsertOrder( ?,?,?,?,?,?,?,?,?,?,?,?,? )}";
$ret = "";
$params = array(
array($_SESSION['usrid'],SQLSRV_PARAM_IN),
array($_SESSION['fwdr'],SQLSRV_PARAM_IN),
array($_POST['liner'],SQLSRV_PARAM_IN),
array($_POST['booking'],SQLSRV_PARAM_IN),
array($_POST['category'],SQLSRV_PARAM_IN),
array($_POST['customsid'],SQLSRV_PARAM_IN),
array($date,SQLSRV_PARAM_IN),
array($_POST['type_of_job'],SQLSRV_PARAM_IN),
array($needweight,SQLSRV_PARAM_IN),
array($needsampl,SQLSRV_PARAM_IN),
array($_SESSION['user'],SQLSRV_PARAM_IN),
array($val,SQLSRV_PARAM_IN),
array($ret,SQLSRV_PARAM_OUT,SQLSRV_PHPTYPE_STRING)
);
$query = sqlsrv_query($conn, $sq, $params);
//var_dump($query);
echo $ret;
// if ($query === false) {
// print_r(sqlsrv_errors());
// }
// header('Location:../insertSpecs.php');
//} else {
// header('Location:../index.php');
//}
?>
what did I do wrong, how can I get return value from my SP...