如何在php上执行sql server存储过程?

时间:2022-09-20 23:47:35

i want to know why i cannot call any stored procedure on php file it always return false but when i call it on sql server directly, it shows my data

我想知道为什么我不能在php文件上调用任何存储过程它总是返回false但是当我直接在sql server上调用它时,它显示我的数据

here is my php:

这是我的PHP:

include ($_SERVER['DOCUMENT_ROOT'] . '/simda/classes/koneksi.php');
global $conn;
$kon = new koneksi();
$conn = $kon->bukaKoneksi();
$params = array();
$query = "EXEC dbo.RptSPJ_Pengeluaran '2013','1','1','1','0','1','1'";

$options = array("Scrollable" => SQLSRV_CURSOR_KEYSET);
$rs_test = sqlsrv_query($conn, $query, $params, $options);
if ($rs_test != NULL) {
    $num_rows = sqlsrv_num_rows($rs_test);
    echo $num_rows;
}
else {
    echo 'wrong';
}

if i echo the query and execute it on sql server, it shows my data is there anything wrong? please help me thank you

如果我回应查询并在sql server上执行它,它显示我的数据是否有任何错误?请帮帮我谢谢

1 个解决方案

#1


3  

read this articles

阅读这篇文章

<?php
$conn = mssql_connect($host, $user, $pass);
mssql_select_db('somedb', $conn);

// Call a simple query
$result = mssql_query('SELECT * FROM sometable', $conn);

// Release the result resource
mssql_free_result($result);

// Then execute the procedure
$proc = mssql_init('some_proc', $conn);
$proc_result = mssql_execute($proc);

// Etc...
mssql_free_statement($proc);
?>

the see this also

看到这个也是

$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
$exec = odbc_exec($conn, "CALL storedProc()");

read these one;;two;;

读这一个;;两个;;

#1


3  

read this articles

阅读这篇文章

<?php
$conn = mssql_connect($host, $user, $pass);
mssql_select_db('somedb', $conn);

// Call a simple query
$result = mssql_query('SELECT * FROM sometable', $conn);

// Release the result resource
mssql_free_result($result);

// Then execute the procedure
$proc = mssql_init('some_proc', $conn);
$proc_result = mssql_execute($proc);

// Etc...
mssql_free_statement($proc);
?>

the see this also

看到这个也是

$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
$exec = odbc_exec($conn, "CALL storedProc()");

read these one;;two;;

读这一个;;两个;;