在SQL Server上,RowCount始终使用存储过程在PHP中返回0
我对该在SQL Server上,RowCount始终使用存储过程在PHP中返回0,php,sql-server,stored-procedures,Php,Sql Server,Stored Procedures,我对该rowCount()函数始终返回0有问题。我已经尝试使用硬代码,但仍然没有显示结果 {“status”:false,“message:“获取报告簿无效!”} 这是我的ReportBook.php <?php header("Content-type: application/json"); include_once 'Database.php'; include_once 'master.php'; //$id_book=$_GET['id_book']; /
rowCount()
函数始终返回0有问题。我已经尝试使用硬代码,但仍然没有显示结果
{“status”:false,“message:“获取报告簿无效!”}
这是我的ReportBook.php
<?php
header("Content-type: application/json");
include_once 'Database.php';
include_once 'master.php';
//$id_book=$_GET['id_book'];
//$TanggalStart = $_GET['TanggalStart'];
//$TanggalEnd = $_GET['TanggalEnd'];
$id_book='KD-BKK-1';
$TanggalStart = '2020-12-22';
$TanggalEnd = '2021-12-31';
// get database connection
$database = new Database();
$db = $database->getConnection();
// prepare province object
$reportbook = new Master($db);
$stmt = $reportbook->GetReportBook($id_book, $TanggalStart, $TanggalEnd);
if($stmt->rowCount() > 0){
// get retrieved row
while($row = $stmt->fetch())
{
// create array
$book_arr[]=array(
"status" => true,
"id_book" => $row['id_book'],
"book_name" => $row['book_name'],
"author" => $row['author'],
"description" => $row['description'],
"book_price" => $row['book_price'],
"id_publication" => $row['id_publication'],
"id_branch" => $row['id_branch'],
"qty" => $row['qty'],
"rental_qty" => $row['rental_qty'],
"imagename" => $row['imagename'],
"imagepath" => $row['imagepath'],
"entry_date" => $row['entry_date'],
);
}
}
else{
$book_arr=array(
"status" => false,
"message" => "Invalid Get Report Book!",
);
}
// make it json format
print_r(json_encode($book_arr));
?>
这是我的SP GetReportBook(它在ASP.NET上工作)
ALTER过程[dbo].[GetReportBook]
(
@id_book varchar(50),
@TanggalStart varchar(50),
@TanggalEnd varchar(50)
)
作为
开始
声明@rowcountint;
开始尝试
从Book中选择TOP 100*;
设置@rowcount=@@rowcount;
结束尝试
开始捕捉
从书本中选择前50个*;
设置@rowcount=@@rowcount;
端接
选择@rowcount;
从书中选择*
(@id\u book=id\u book或id\u book=id\u book)
和(@TanggalStart='ALL'或Convert(Varchar,entry\u date,112)>=@TanggalStart)和(@TanggalEnd='ALL'或Convert(Varchar,entry\u date,112)该函数在选择上不起作用:
添加、删除或更改的行数
如果关联PDO语句执行的最后一条SQL语句是SELECT语句,则PDO::CURSOR\u FWDONLY游标返回-1。PDO::CURSOR\u可滚动游标返回结果集中的行数
因此,只需读取所有行,然后测试数组大小
while($row = $stmt->fetch())
{
// create array
$book_arr[]=array(
"status" => true,
"id_book" => $row['id_book'],
"book_name" => $row['book_name'],
"author" => $row['author'],
"description" => $row['description'],
"book_price" => $row['book_price'],
"id_publication" => $row['id_publication'],
"id_branch" => $row['id_branch'],
"qty" => $row['qty'],
"rental_qty" => $row['rental_qty'],
"imagename" => $row['imagename'],
"imagepath" => $row['imagepath'],
"entry_date" => $row['entry_date'],
);
}
if ($row = 0) {
$book_arr=array(
"status" => false,
"message" => "Invalid Get Report Book!",
);
}
是的,我正在使用PDO_SQLSRVi。看到了。这个问题的解决方案了吗?我已经研究过了,但仍然没有得到它的详细属性:PDOStatement::$book_arr在C:\xampp\htdocs\library api\reportbook.php第42ok行。我的问题已经解决了。谢谢
while($row = $stmt->fetch())
{
// create array
$book_arr[]=array(
"status" => true,
"id_book" => $row['id_book'],
"book_name" => $row['book_name'],
"author" => $row['author'],
"description" => $row['description'],
"book_price" => $row['book_price'],
"id_publication" => $row['id_publication'],
"id_branch" => $row['id_branch'],
"qty" => $row['qty'],
"rental_qty" => $row['rental_qty'],
"imagename" => $row['imagename'],
"imagepath" => $row['imagepath'],
"entry_date" => $row['entry_date'],
);
}
if ($row = 0) {
$book_arr=array(
"status" => false,
"message" => "Invalid Get Report Book!",
);
}