我已经在这里和其他资源中搜索了此问题的解决方案,但到目前为止还没有找到解决问题的答案。
当尝试从 MS SQL 2008 数据库中查询和获取结果时,我在 sqlsrv_query 行中得到一个数组到字符串的转换错误。
这是用于访问和查询的 php 代码。
<?php
/* Specify the server and connection string attributes. */
$serverName = "DATABASE";
$connInfo = array( "Database"=>"Suggestion");
$conn = sqlsrv_connect( $serverName, $connInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$query = "SELECT * FROM dbo.Suggestions";
$result = sqlsrv_query($conn, $query) OR die(sqlsrv_errors());
$val=sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC);
echo $val;
?>
编辑: 根据要求,下面的实际错误代码:
注意:第 24 行 C:\wamp\www\DBTest\index.php 中的数组到字符串转换
当考虑到整个文件 index.php 的上下文时,第 24 行是:
$result = sqlsrv_query($conn, $query) OR die(sqlsrv_errors());
提前感谢您的帮助!