2017-02-06 4 views
-1

PHPとストアドプロシージャに加えてエラーコードも記載されています... 私はmysqliを試しましたが、何をすべきか?PHPを使用してストアドプロシージャのSQL Server 2012にデータを挿入することができない

<?php 

$serverName = "DESKTOP-FBUSVI6\RETAILAPP12"; //serverName\instanceName 

// Since UID and PWD are not specified in the $connectionInfo array, 
// The connection will be attempted using Windows Authentication. 
$connectionInfo = array("Database"=>"RetailLink"); 
$conn = sqlsrv_connect($serverName, $connectionInfo); 

if($conn) { 
    echo "Connection established.<br />"; 
}else{ 
    echo "Connection could not be established.<br />"; 
    die(print_r(sqlsrv_errors(), true)); 
} 


$sql = "CALL [dbo].[sp_mRetailerRegInfo_Add] ('HUUSAUS','HAHShsg','[email protected],com','923224024386')"; 
$stmt = sqlsrv_query($conn, $sql); 
if($stmt == false) { 
die(print_r(sqlsrv_errors(), true)); 
} 
else 
{ 
echo "Record add successfully"; 
} 
sqlsrv_close($conn); 

?> 

USE [RetailLink] 
GO 

/****** Object: StoredProcedure [dbo].[sp_mRetailerRegInfo_Add] Script Date: 2/5/2017 9:54:01 PM ******/ 
SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 


CREATE PROC [dbo].[sp_mRetailerRegInfo_Add] 

    @Name nvarchar(200), 
    @ContactPerson nvarchar(200), 
    @Email nvarchar(200), 
    @ContactNo nvarchar(20), 
    @RetailerCode nvarchar(20) output, 
    @ErrorCode nvarchar(10) output 


AS 
    SET NOCOUNT ON 
    SET XACT_ABORT ON 

    declare @ActiveFlag char(1) 
    declare @CreationDate datetime 
    declare @LastUpdateBy int 
    declare @LastUpdateDate datetime 

    set @ActiveFlag = 'N' 
    set @CreationDate = GetDate() 
    set @LastUpdateDate = GetDate() 
    set @LastUpdateBy = 0 

    if @Name is Null 
    begin 
     set @ErrorCode = '-101' --Retail Name Blank 
     return 
    end 

    if @ContactPerson is Null 
    begin 
     set @ErrorCode = '-102' --Contact Person Blank 
     return 
    end 

    if @Email is Null 
    begin 
     set @ErrorCode = '-103' --Email Blank 
     return 
    end 

    if @ContactNo is Null 
    begin 
     set @ErrorCode = '-104' --Contact Number blank 
     return 
    end 

    if exists (select NULL 
        from mRetailerRegInfo 
        where RetailerCode = @RetailerCode) 
    begin 
     set @ErrorCode = '-202' --Retailer Code exist! Please contact administrator! 
     return 
    end 


    BEGIN TRAN 

    set @RetailerCode = dbo.fGetRetailerCode() 
    set @ErrorCode = NULL --Registration Success 

    INSERT INTO [dbo].[mRetailerRegInfo] ([RetailerCode], [Name], [ContactPerson], [Email], [ContactNo], [ActiveFlag], [CreationDate], [LastUpdateBy], [LastUpdateDate]) 
    SELECT @RetailerCode, @Name, @ContactPerson, @Email, @ContactNo, @ActiveFlag, @CreationDate, @LastUpdateBy, @LastUpdateDate 

    ---- Begin Return Select <- do not remove 
    --SELECT [RetailerID], [DistribID], [RetailerAccCode], [RetailerName], [Addr1], [Addr2], [Addr3], [PostalCode], [Email], [Phone], [Fax], [Mobile], [ContactFName], [ContactLName], [ContactTitle], [ActiveFlag], [Status], [CreationDate], [LastUpdateBy], [LastUpdateDate] 
    --FROM [dbo].[mRetailer] 
    --WHERE [RetailerID] = SCOPE_IDENTITY() 
    --  AND [DistribID] = @DistribID 
    --  AND [RetailerAccCode] = @RetailerAccCode 
    ---- End Return Select <- do not remove 

    COMMIT 


GO 



------------------------------- 
Connection established. 
Array ([0] => Array ([0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '.'. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Incorrect syntax near '.'.)) 

答えて

0

使用EXECおよび削除ブラケット:

$sql = "EXEC [dbo].[sp_mRetailerRegInfo_Add] 'HUUSAUS','HAHShsg','[email protected],com','923224024386'"; 
$stmt = sqlsrv_query($conn, $sql); 
if($stmt == false) { 
die(print_r(sqlsrv_errors(), true)); 
関連する問題