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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18418151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:31:35  来源:igfitidea点击:

how to execute sql server stored procedure on php?

phpsqlstored-procedures

提问by Christianto Hermawan

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 上执行它,它会显示我的数据有什么问题吗?请帮助我谢谢

回答by krishna

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;;

阅读这些;; ;;