php中怎样遍历sqlserver数据?

WBOY
Release: 2016-06-06 20:33:28
Original
1026 people have browsed it

<code>$serverName = "192.168.135.211";
$connectionInfo = array( 
"Database"=>"AGGCRMTEST", "UID"=>"sa", "PWD"=>"123213");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
    echo "Could not connect.\n";
    die( print_r( sqlsrv_errors(), true));
}
$tsql = "exec [GetListByName] 'o'";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
    echo "Statement 1 could not be executed.";
    die( print_r( sqlsrv_errors(), true));
}else{
   $qty = sqlsrv_fetch_array( $stmt);
   sqlsrv_free_stmt( $stmt);
}</code>
Copy after login
Copy after login

怎样一个一个的取到数据啊。。。。。。。。。。。。。。(让数据一个一个的显示出来)

回复内容:

<code>$serverName = "192.168.135.211";
$connectionInfo = array( 
"Database"=>"AGGCRMTEST", "UID"=>"sa", "PWD"=>"123213");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
    echo "Could not connect.\n";
    die( print_r( sqlsrv_errors(), true));
}
$tsql = "exec [GetListByName] 'o'";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
    echo "Statement 1 could not be executed.";
    die( print_r( sqlsrv_errors(), true));
}else{
   $qty = sqlsrv_fetch_array( $stmt);
   sqlsrv_free_stmt( $stmt);
}</code>
Copy after login
Copy after login

怎样一个一个的取到数据啊。。。。。。。。。。。。。。(让数据一个一个的显示出来)

<code>php</code><code>$result = array();
while($qty = sqlsrv_fetch_array( $stmt)){
    $result[] = $qty;
}
sqlsrv_free_stmt( $stmt);

</code>
Copy after login

我插一句,建议你用PDO,之前也是用sqlsrv 后来发现有些字符显示不出来而且INPUT/OUTPUT都需要ICONV转换编码,最后换PDO解决了

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!