Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 执行PDO存储过程时出错_Php_Sql_Sql Server_Apache - Fatal编程技术网

Php 执行PDO存储过程时出错

Php 执行PDO存储过程时出错,php,sql,sql-server,apache,Php,Sql,Sql Server,Apache,执行下面的代码时,我在下面得到一个错误 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near '@P1'.' in E:\xampp\htdocs\kbs\inc\settings_inc.php:62 Stack trace: #0 E:

执行下面的代码时,我在下面得到一个错误

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: 
[Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near '@P1'.' in 
E:\xampp\htdocs\kbs\inc\settings_inc.php:62 Stack trace: #0 
E:\xampp\htdocs\kbs\inc\settings_inc.php(62): PDOStatement->execute() #1 
E:\xampp\htdocs\kbs\settings.php(186): include('E:\xampp\htdocs...') #2 {main} thrown in 
E:\xampp\htdocs\kbs\inc\settings_inc.php on line 62
我们将不胜感激

ALTER PROCEDURE [dbo].[sp_AddEditCustomers]
@customerid         int=0,
@fname              Varchar(15),
@mname              Varchar(15)='',
@lname              Varchar(15)='',
@caddress           Varchar(50)='',
@pcode              Varchar(5)='',
@town               Varchar(25)='',
@mobileno1          varchar(12)='',
@mobileno2          varchar(12)='',
@modifyby           varchar(15)='System',
@isedit             int=0   
AS
BEGIN
DECLARE @AccountID              int
DECLARE @AccCount               int

-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON;
-- Generate Client Account Number
IF (@isedit)=0
BEGIN TRY
SET @AccCount=(SELECT COUNT(AccountID) From t_tmp_AccountID)

IF (@AccCount)=0
BEGIN
SET @AccountID=100000
INSERT INTO t_tmp_AccountID SELECT @AccountID
END
ELSE
SET @AccountID=(SELECT (MAX(AccountID) +1) FROM t_tmp_AccountID)

INSERT INTO t_tmp_AccountID SELECT @AccountID

-- END Generate Client Account Number

INSERT INTO t_cust_customer (CustomerAccNo,FName,MName,LName,CAddress,PCode,Town,MobileNo1,MobileNo2,CreateDate,ModifiedDate,Modifyby)
VALUES
(@AccountID,@fname,@mname,@lname,@caddress,@pcode,@town,@mobileno1,@mobileno2,GETDATE(),GETDATE(),@modifyby);
END TRY
BEGIN CATCH
SELECT 
ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH
IF (@isedit)=1
BEGIN TRY
UPDATE t_cust_customer
SET
FName=@fname,
MName=@mname,
LName=@lname,
CAddress=@caddress,
PCode=@pcode,
Town=@town,
MobileNo1=@mobileno1,
MobileNo2=@mobileno2,
ModifiedDate=GETDATE(),
ModifyBy=@modifyby
WHERE
CustomerID=@customerid
END TRY
BEGIN CATCH
SELECT 
ERROR_NUMBER() AS ErrorNumber
,ERROR_MESSAGE() AS ErrorMessage;
END CATCH
END
//PHP代码

$clientID=0;
$isEdit=0;
$stmt = $conn->prepare("EXECUTE sp_AddEditCustomers(?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bindParam(1, $clientID, PDO::PARAM_INT); 
$stmt->bindParam(2, $_POST[FName], PDO::PARAM_STR, 15);
$stmt->bindParam(3, $_POST[MName], PDO::PARAM_STR, 15);
$stmt->bindParam(4, $_POST[LName], PDO::PARAM_STR, 15);
$stmt->bindParam(5, $_POST[CAddress], PDO::PARAM_STR, 50);
$stmt->bindParam(6, $_POST[PCode], PDO::PARAM_STR, 5);
$stmt->bindParam(7, $_POST[PCode], PDO::PARAM_STR, 5);
$stmt->bindParam(8, $_POST[Town], PDO::PARAM_STR, 25);
$stmt->bindParam(9, $_POST[CMobile1No1], PDO::PARAM_STR, 12);
$stmt->bindParam(10, $_POST[CMobile1No2], PDO::PARAM_STR, 12);
$stmt->bindParam(11, $UserName, PDO::PARAM_STR, 15);
$stmt->bindParam(12, $isEdit, PDO::PARAM_INT, 15);
$stmt->execute();
下面是来自探查器的输出。在这里它得到了错误的语法错误。我在执行时也会遇到同样的错误

declare @p1 int
set @p1=NULL
declare @p5 nvarchar(max)
set @p5=NULL
declare @p6 nvarchar(max)
set @p6=NULL
declare @p7 nvarchar(max)
set @p7=NULL
declare @p8 nvarchar(max)
set @p8=NULL
declare @p9 nvarchar(max)
set @p9=NULL
declare @p10 nvarchar(max)
set @p10=NULL
declare @p11 nvarchar(max)
set @p11=NULL
declare @p12 nvarchar(max)
set @p12=NULL
declare @p13 nvarchar(max)
set @p13=NULL
declare @p14 nvarchar(max)
set @p14=NULL
exec sp_prepexec @p1 output,N'@P1 int,@P2 nvarchar(max) OUTPUT,@P3 nvarchar(max) OUTPUT,@P4 nvarchar(max) OUTPUT,@P5 nvarchar(max) OUTPUT,@P6 nvarchar(max) OUTPUT,@P7 nvarchar(max) OUTPUT,@P8 nvarchar(max) OUTPUT,@P9 nvarchar(max) OUTPUT,@P10 nvarchar(max) OUTPUT,@P11 nvarchar(max) OUTPUT',N'EXECUTE sp_AddEditCustomers(@P1,@P2 OUTPUT,@P3 OUTPUT,@P4 OUTPUT,@P5 OUTPUT,@P6 OUTPUT,@P7 OUTPUT,@P8 OUTPUT,@P9 OUTPUT,@P10 OUTPUT,@P11 OUTPUT)',0,@p5 output,@p6 output,@p7 output,@p8 output,@p9 output,@p10 output,@p11 output,@p12 output,@p13 output,@p14 output
select @p1, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14

此存储过程中没有
@P1
?@P1是在执行期间由sql server准备的语句生成的。我已通过探查器进行了跟踪,这是传递给sql server的内容。