How to store a multi-field record set to a multi-dimensional array using the functions of the com component

Source: Internet
Author: User
How to use the functions of the com component to store the multi-field record set in the multi-dimensional array php5.4 use com to connect to the phd database. This database is special, and the table name and field are not easy to write. it is a database of honeywell. Com query returns multiple records and multiple fields. I want to perform arithmetic operations on a field and do not know how to operate it. I am a newbie, online data query indicates that records are stored in multi-dimensional arrays, so php is not supported. please help me! Thank you!
For example, to query the scores of students in the 0601 class, multiple records are returned. each record contains the class, student ID, name, subject (language), and score fields. How to use the com component function to save the record set to a multi-dimensional array, just operate on the array, I will almost.

$ Conn = new COM ("ADODB. Connection ");
$ Connstr = "... omitted ";
$ Conn-> Open ($ connstr );
$ Starttime = "08:30:00 ";
$ SQL = "Select banji, sno, name, kemu, chengji FROM stu_cj WHERE banji = '000000' AND kemu = 'yuwen '";
$ Stmt = $ conn-> Execute ($ SQL );
How to use the com function to store the record set $ stmt to a multi-dimensional array and operate the array


Reply to discussion (solution)

I don't know what the phd database is.
However, since we can use ADODB. Connection to connect, there is obviously no big problem.
Able to write

$stmt = $conn->Execute($sql);while(! $stmt->eof) {  $res[] = arraay(    'banji' => $stmt->fields['banji']->value,     'sno' => $stmt->fields['sno']->value,    'name' => $stmt->fields['name']->value,    'kemu' => $stmt->fields['kemu']->value,    'chengji' => $stmt->fields['chengji']->value,  );  $stmt->MoveNext();}
In short, it is basically the same as asp.

You can also use the obcd function group to perform operations.

Thank you very much for your answers and new knowledge.

I encountered another problem. after your instruction, you successfully stored the queried record set in the array. However, if multiple classes and one class have an array after the query, can I store the class name together with the array queried by each class in an array? I don't know. I don't know. it's just like class 0601, and res []; class 0602 and res []. And save it to the array. Different classes get different res. they want to store them together in an array, how to do it, and how to reference a value.

Array (
'1970 class' => array ();
'1970 class' => array ();
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.