- Require 'dbconn. php ';
- $ SQL = 'select * from _ test ';
- $ Query = mssql_query ($ SQL );
- While ($ row = mssql_fetch_row ($ query ))
- {
- Echo $ row ['userid']. ':'. $ row [1].'
';
- }
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: Wang Xiao'er Notice: Undefined index: UserId in D:/_ PHP_Test/Test2/test_connLocalDB.php on line 32: Wang xiaosan Notice: undefined index: UserId in D:/_ PHP_Test/Test2/test_connLocalDB.php on line 32: Wang Xiaosi Notice: Undefined index: UserId in D: /_ PHP_Test/Test2/test_connLocalDB.php on line 32: Wang Xiaowu Analysis: mssql_fetch_row (), which is exactly the same as mssql_fetch_array () and the Second Optional parameter MYSQL_NUM. Obtain a row of data from the result set associated with the specified result ID and return it as an array. Each result column is stored in an array unit, and the offset starts from 0. Note: Here the offset starts from 0. you cannot use the key value (field name) to take the value. you can only use the index to take the value. Therefore, $ row ['key value'] cannot be used to obtain the value. 2. example of method name mssql_fetch_assoc:
- $ Query = mssql_query ($ SQL );
- While ($ row = mssql_fetch_assoc ($ query ))
- {
- Echo $ row ['userid']. ':'. $ row [1].'
';
- }
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_con NLocalDB. php on line 43 5: Analysis: mssql_fetch_assoc () is exactly the same as using mssql_fetch_array () and the Second Optional parameter MYSQL_ASSOC. It only returns the associated array. This is also the initial working method from mssql_fetch_array. Therefore, $ row [index value] cannot be used to obtain the value. III. example of method name mssql_fetch_array:
- $ Query = mssql_query ($ SQL );
- While ($ row = mssql_fetch_array ($ query ))
- {
- Echo $ row ['userid']. ':'. $ row [1].'
';
- }
- ?>
Return value: 1: Wang Xiaoyi 2: Wang Xiao'er 3: Wang xiaosan 4: Wang Xiaosi 5: Wang Xiaowu Analysis: mssql_fetch_array (), which is an extended version of mssql_fetch_row. In addition to storing data in an array as a digital index, you can also store data as an associated index and use the field name as the key name. Therefore, both $ row ['key value'] and $ row [index value] can be used here. In mssql_fetch_array (), the second parameter result_type (which is a constant) is an optional parameter. the optional values include MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH. Where: mssql_fetch_array ($ query, MYSQL_ASSOC) = explain ($ query); mssql_fetch_array ($ query, MYSQL_NUM) = mssql_fetch_row ($ query); so mssql_fetch_array () to some extent, a function can be regarded as a collection of mssql_fetch_row () and mssql_fetch_assoc. Therefore, mssql_fetch_array () also has the MYSQL_BOTH parameter, and an array containing both the correlation and numerical indexes is obtained. IV. example of method name mssql_fetch_object:
- $ Query = mssql_query ($ SQL );
- While ($ row = mssql_fetch_object ($ query ))
- {
- Echo $ row-> UserId. ':'. $ row-> CreateTime ."
";
- }
Return value: 1: 06 7 2011 4: 46PM2: 06 7 2011 4: 46PM3: 06 7 2011 4: 46PM4: 06 7 2011 4: 46PM5 :: 06 7 2011 PM Analysis:Mysql_fetch_object () is similar to mssql_fetch_array. only one difference is that an object is returned instead of an array and the field name is used as an attribute. Indirectly, it also means that you can only access it by field name, rather than offset. |