简体   繁体   中英

Return Data using Stored Procedure in AdoDB PHP

I am using MS SQL Server 2008 as my Database and I created a Stored Procedure that looks like this.

USE [DB_Question]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Check_ExamID]
@ExamID NVARCHAR(MAX)
as
SELECT * FROM TBL_ExamTimer WHERE ExamID = @ExamID

and here is my PHP code that suppost to be the target is to display data in my PHP site by using some criteria also.

<html>
<head>

</head>
<body>
<?php

    include('config.php');
    include('adodb/adodb.inc.php');
    $db = ADONewConnection($dbdriver);
    $db->Connect($dsn, $username, $password);

    $procedure = $db->prepareSp('Check_ExamID');
    if (!$procedure)
    die ('Invalid or inaccessible stored procedure name');

    $parameter1Name = '@ExamID';
    $ok = $db->inParameter($procedure,$parameter1Name,'1234');
    $result = $db->execute($procedure);


?> 
</body>
</html>

I am trying to display data where ExamID =@ExamID or 1234 for param of @ExamID

My Target here is to use my stored procedure to select data in my table and return it back in my php file but nothings happening. TYSM

In the first instance, the parameters must be strings passed by reference, so the correct syntax is:

$parameter1Name = '@ExamID';
$parameter1Value = '1234';

$ok = $db->inParameter($procedure,$parameter1Name,$parameter1Value);
$result = $db->execute($procedure);

I tried, but if i use inParameter it isn´t right. I have php 5.4.45, Adodb 5 and mssql 8.0 I write my code.

//connection
$conexion = &ADONewConnection('odbc_mssql');
$datos_sql = "Driver={SQL Server};Server=$nameServer;Database=$nameBD;";
$conexion -> Connect($datos_sql, $user, $password);
$procedure = $conexion ->prepareSP('Test');
//This is the in parameter
$paramName1='@articulo';
$paramValour1='90.27.05';
conexion ->inParameter($procedure,$paramName1,  $paramValour1);
if (!$procedure)
    die ('Invalid or inaccessible stored procedure name');
$result = $conexion ->execute($procedure) or die($conexion ->ErrorMsg());
while($r = $result->fetchRow())
    print_r($r);

Stored Procedure

ALTER PROCEDURE [dbo].[Test] (@articulo VARCHAR(30))
AS
SET NOCOUNT ON

SELECT Peso
    ,CodigoArticulo
FROM maestro_articulos
WHERE codigoarticulo LIKE @articulo;

RETURN

The error is:

[Microsoft][ODBC SQL Server Driver][SQL Server]The procedure 'Test' requires the parameter '@articulo', which was not specified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM