我对 SQL-Server 和 PHP 相当陌生,但我正在尝试使用 PHP 获取表中的总行数。
这是我正在使用的代码,它连接得很好,但它不会打印行数:
<?php
$serverName = "SERVER1\SQLEXPRESS";
$connectionInfo = array( "Database"=>"petitionlist");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
?>
<b>Error: </b>Could not connect to the server database.
<?php
die( print_r( sqlsrv_errors(), true));
}
$tsql = "Select Count(*) from SignatureTable";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
?>
<b>Error: </b>
<?php
die( print_r( sqlsrv_errors(), true));
}
?>
<b>Result:</b><br />
<?php
print_r(sqlsrv_fetch_object($stmt));
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
如果我在 SQL Server Studio 上执行“Select Count(*) from SignatureTable”命令,它将返回正确的数字。所以这不是我的服务器,而是我的代码。
我相信您的来电
print_r(sqlsrv_fetch_object($stmt));
可能是错的。至少查看有关如何进行调用的文档表明那里可能存在错误。
http://www.php.net/manual/en/function.sqlsrv-fetch-object.php
您可能想尝试使用 fetch 而不是 fetch-object。我建议遵循这个例子。
http://www.php.net/manual/en/function.sqlsrv-fetch.php
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)