in Education by
I am running following PHP code to interact with a 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"); Using ($rs_select -> RecordCount) gives -1 though the query is returning non-zero records. (a) What can be the reason? (b) Is there any way out? I have also tried using count($rs_select -> GetRows()). This satisfies the need but looks inefficient as it will involve copying of all the records into an array first. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
ADODB has its own rules for what recordcount is returned depending on the type of recordset you've defined. See: MS Knowledge Base article 194973 W3C Schools article In the example above, the PHP COM() object is used to instantiate ADODB, a COM interface for generic database access. According to the PHP documentation, the object reference produced is overloaded, so you can just use the same properties/methods that the native ADODB object would have. This means that you need to use the ADODB methods to set the recordset type to one that will give an accurate recordcount (if you must have it). The alternative, as others have mentioned, is to use a second query to get the COUNT() of the records returned by the SELECT statement. This is easier, but may be inappropriate in the particular environment. I'm not an ADO guru, so can't provide you with the exact commands for setting your recordset type, but from the articles cited above, it is clear that you need a static or keyset cursor. It appears to me that the proper method of setting the CursorType is to use a parameter in the command that opens the recordset. This W3C Schools article on the CursorType property gives the appropriate arguments for that command. Hopefully, this information will help the original poster accomplish his task, one way or the other.

Related questions

0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    I am running following PHP code to interact with a MS Access database. $odbc_con = new COM("ADODB. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    BRAIN DEVELOPER A. Fill in the blanks: 1. 2. A. is an organised way of storing information, A relational ... Syntax Kips 18 File Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    How many records can a select query return? How many records can a SOSL query return?...
asked Nov 11, 2020 in Technology by JackTerrance
0 votes
    In Ms Access Which query allow to create a table or alter data or database? Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    Data can be inserted, updated and deleted from a table by using a __________ object in ms access Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    data can be inserted, updated and deleted from a table by using _______ object on MS access Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    State True or False: MS Access is a Database Management System. 2 Database is of two types, DBMS and RDBMS. 3 ... called a field name. Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    I am retrieving messages from an Outlook account. I am trying to get inline files and attachments from ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I am struggling trying to update a row in an Azure SQL database. What I am trying to do is to ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    Which product is returned in a join query have no join condition: (a) Equijoins (b) Cartesian (c) ... Answers, Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    An application developer can guard against certain snapshot anomalies by appending a ______ clause to the SQL ... topic in section Concurrency Control of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    This question already has answers here: PHP parse/syntax errors; and how to solve them (21 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
...