PHP and MS Access: the number of records returned by a SELECT query

I am running the following PHPcode to interact with an MS Access database.

$odbc_con = new COM("ADODB.Connection");
$constr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . $db_path . ";";
$odbc_con -> open($constr);

$rs_select = $odbc_con -> execute ("SELECT * FROM Main");

Usage ($rs_select -> RecordCount)gives -1, although the query returns non-zero entries.

(a) What is the reason? (b) Is there a way out?

I also tried to use count($rs_select -> GetRows()). This satisfies the need, but looks inefficient, since it involves first copying all the records into an array.

+3
source share
5 answers

ADODB has its own rules by which a record is returned, depending on the type of record set that you define. Cm:

Knowledge Base Article 194973

W3C School Article

PHP COM() ADODB, COM- . PHP, , /, ADODB-, , ADODB, , ( ). , , COUNT() , SELECT. , .

ADO, , , . , CursorType , . W3C Schools CursorType .

, .

+1

, ODBC . , recordcount . , , , .

, SELECT COUNT(*) . , 2 - , .

+1

COUNT? :

$rs_select = $odbc_con -> execute ("SELECT COUNT(*) FROM Main");
0

, Access , ( ) - .

, . VBA foo.MoveLast foo.MoveFirst - , php-. , , , , .

( , , VBA, , , )

0

If you use the dynamic connection type with the cursor, it can really change. Someone may delete a record from this database while viewing record pages. To avoid this, use the static view of the snapshot cursor. I have this bookmark that will explain this well. It always called me, and the bookmark always reminded me why.

http://support.microsoft.com/kb/194973

-1
source

Source: https://habr.com/ru/post/1697445/


All Articles