doubu7425 2013-07-24 12:07
浏览 10

使用SQL 2008和PHP进行数组到字符串转换

I have searched around here and other sources for a solution to this issue but so far no luck finding the answer that solves the issue.

When trying to query and fetch the result from a MS SQL 2008 database I get an Array to string conversion error in the sqlsrv_query line.

This is the php code for accessing and querying.

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

?>

EDIT: As requested the actual error code below:

Notice: Array to string conversion in C:\wamp\www\DBTest\index.php on line 24

When taken into context of the entire file index.php line 24 is:

$result = sqlsrv_query($conn, $query) OR die(sqlsrv_errors());

Thanks in advance for any help!

  • 写回答

1条回答 默认 最新

  • dongping9475 2013-07-24 12:29
    关注

    You can not print an array with 'echo' you have to use either 'print_r()' or var_dump()

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致