Method Name: Mssql_fetch_row ()
Test:
Copy Code code as follows:
Require ' dbconn.php ';
$sql = ' select * from _test ';
$query = Mssql_query ($sql);
while ($row =mssql_fetch_row ($query))
{
echo $row [' UserId ']. ':: '. $row [1]. ' <br> ';
}
Return:
notice:undefined Index:userid in d:/_php_test/test2/test_connlocaldb.php on line 32:: Wang Xiaoyi
notice:undefined Index:userid in d:/_php_test/test2/test_connlocaldb.php on line 32:: Wangxiao
notice:undefined Index:userid in d:/_php_test/test2/test_connlocaldb.php on line 32:: Wangxiao
notice:undefined Index:userid in d:/_php_test/test2/test_connlocaldb.php on line 32:: Wangxiaoxi
notice:undefined Index:userid in d:/_php_test/test2/test_connlocaldb.php on line 32:: Wang Xiao
Analysis:
Mssql_fetch_row () is exactly the same as using Mssql_fetch_array () plus the second optional parameter mysql_num. Gets a row of data from the result set associated with the specified result identity and returns as an array. The columns of each result are stored in a cell of an array, with an offset starting at 0. Note that this is offset from 0 and cannot be evaluated with the key value (the field name) and can only be evaluated using the index. Therefore, the value cannot be fetched using the $row[' key value '.
Method Name: Mssql_fetch_assoc ()
Test:
Copy Code code as follows:
$query = Mssql_query ($sql);
while ($row =mssql_fetch_assoc ($query))
{
echo $row [' UserId ']. ':: '. $row [1]. ' <br> ';
}
Return:
notice:undefined offset:1 in d:/_php_test/test2/test_connlocaldb.php on line 43 1::
notice:undefined offset:1 in d:/_php_test/test2/test_connlocaldb.php on line 43 2::
notice:undefined offset:1 in d:/_php_test/test2/test_connlocaldb.php on line 43 3::
notice:undefined offset:1 in d:/_php_test/test2/test_connlocaldb.php on line 43 4::
notice:undefined offset:1 in d:/_php_test/test2/test_connlocaldb.php on line 43 5::
Analysis:
Mssql_fetch_assoc () and Mssql_fetch_array () plus the second optional parameter Mysql_assoc exactly the same. It simply returns an associative array. This is also the initial working method of Mssql_fetch_array (). Therefore, the value cannot be fetched with the $row[index value].
Method Name: Mssql_fetch_array ()
Test:
Copy Code code as follows:
<?php
$query = Mssql_query ($sql);
while ($row =mssql_fetch_array ($query))
{
echo $row [' UserId ']. ':: '. $row [1]. ' <br> ';
}
?>
Return:
1:: Wang Xiaoyi
2:: Wangxiao
3:: Wangxiao
4:: Wangxiaoxi
5:: Wang Xiao
Analysis:
Mssql_fetch_array () is an extended version of Mssql_fetch_row (). In addition to storing data in an array as a digital index, you can store the data as an associated index, using the field name as the key name. So you can use the $row[' key value ' and the $row[index value to get the value here.
The second parameter result_type (which is a constant) in Mssql_fetch_array () is an optional parameter, and the value range is: Mysql_assoc, Mysql_num, and Mysql_both. which
Mssql_fetch_array ($query, mysql_assoc) = = Mssql_fetch_assoc ($query);
Mssql_fetch_array ($query, mysql_num) = = Mssql_fetch_row ($query);
So the Mssql_fetch_array () function can in some way be considered a collection of Mssql_fetch_row () and Mssql_fetch_assoc (). Therefore, the Mssql_fetch_array () also has the Mysql_both parameter, which will result in an array containing both the association and the numeric index.
Method Name: Mssql_fetch_object ()
Test:
Copy Code code as follows:
$query =mssql_query ($sql);
while ($row =mssql_fetch_object ($query))
{
echo $row->userid. ':: '. $row->createtime. " <br> ";
}
Return:
1::06 7 4:46pm
2::06 7 4:46pm
3::06 7 4:46pm
4::06 7 4:46pm
5::06 7 4:46pm
Analysis:
Mysql_fetch_object () and Mssql_fetch_array are similar, with only one difference, that is, returning an object instead of an array and making the field name a property. Indirectly, it also means that you can only access the word Chinalai, not the offset.