AdoDB, setting the index of the RS from the database to extract the data is a digital or field name

xiaoxiao2021-03-06  19

$ AdoDb_fetch_mode

This is a global variable that determines how arrays are retrieved by recordsets. The recordset saves this value on creation (eg. In Execute () or SelectLimit ()), and any subsequent changes to $ ADODB_FETCH_MODE have no affect on existing recordsets, only on Recordsets created in the fulure.

The Following Constants Are Defined:

Define ('adoDb_fetch_default'; define ('adoDb_fetch_num', 1); define ('adoDb_fetch_assoc', 2); define ('adoDb_fetch_both', 3);

AN EXAMPLE:

$ ADODB_FETCH_MODE = ADODB_FETCH_NUM; $ rs1 = $ db-> Execute ( 'select * from table'); $ ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; $ rs2 = $ db-> Execute ( 'select * from table'); print_r ($ rs1-> Fields; # shows array ([0] => 'V0', [1] => 'V1') Print_R ($ r2-> fields); # shows array (['col1'] => 'V0', [ 'col2'] => 'V1')

As you can see in the Above Example, Both Recordsets Store and Use Different Fetch Modes Based on The $ adoDB_Fetch_Mode Setting When the Recordset Was Created By EXECUTE ().

If no fetch mode is predefined, the fetch mode defaults to ADODB_FETCH_DEFAULT. The behaviour of this default mode varies from driver to driver, so do not rely on ADODB_FETCH_DEFAULT. For portability, we recommend sticking to ADODB_FETCH_NUM or ADODB_FETCH_ASSOC. Many drivers do not support ADODB_FETCH_BOTH .

SetFetChmode Function

Some programmers prefer to use a more object-oriented solution, where the fetch mode is set by a object function, SetFetchMode. Once this function is called for a connection object, that connection object will ignore the global variable $ ADODB_FETCH_MODE and will use the internal fetchMode property exclusively $ db-> setFetchMode (ADODB_FETCH_NUM);. $ rs1 = $ db-> Execute ( 'select * from table'); $ db-> setFetchMode (ADODB_FETCH_ASSOC); $ rs2 = $ db-> Execute ( 'select * from table '); Print_R ($ r1-> fields); # shows array ([0] =>' V0 ', [1] =>' V1 ') Print_R ($ r2-> fields); # shows array ( ['COL1'] => 'V0', ['COL2'] => 'V1')

To Retrieve the Previous Fetch Mode, You Can Use Check The $ db-> fetchmode property, or use the return value of setfetchmode ().

转载请注明原文地址:https://www.9cbs.com/read-44101.html

New Post(0)