Viewed   289 times

I have no experience with access.

How to do update/insert/delete/select statement with and without $rs = new com("ADODB.RecordSet"); ?

 Answers

5

PDO

If you want to interface with an MS Access database using PHP, PDO is available for you.

<?php
    try {
        $pdo = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:accounts.mdb;Uid=Admin");
    }
    catch (PDOException $e) {
        echo $e->getMessage();
    } 

When using PDO, due to the unified interface for DB operations, you have the opportunity to make your app more portable across various RDBMs systems. All you have to do is to provide the connection string to the PDO new instance and have the correct PDO driver installed.

As the result of this unified interface, your application can be easily ported from MS Access to MySQL, SQLite, Oracle, Informix, DB2, etc. which most certainly is the case if it ages enough.

Here's an insertion example:

<?php
try {
   // Connect, 
   // Assuming that the DB file is available in `C:animals.mdb`
   $pdo = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:animals.mdb;Uid=Admin");

    // INSERT data
    $count = $pdo->exec("INSERT INTO animals(animal_type, animal_name) VALUES ('kiwi', 'troy')");

    // echo the number of affected rows
    echo $count;

    // close the database connection
    // See: http://php.net/manual/en/pdo.connections.php
    $pdo = null;
}
catch (PDOException $e) {
    echo $e->getMessage();
}

ODBC

In case you don't want to use PDO for some insane reasons, you can look into ODBC.

Here's an example:

<?php

if (! $conn = odbc_connect('northwind', '', '')) {
    exit("Connection Failed: $conn");
}

if (! $rs = odbc_exec($conn, 'SELECT * FROM customers')) {
    exit('Error in SQL');
}

while (odbc_fetch_row($rs)) {
  echo 'Company name: ', odbc_result($rs, 'CompanyName'), PHP_EOL;
  echo 'Contact name: ', odbc_result($rs, 'ContactName'), PHP_EOL;
}

odbc_close($conn);
Saturday, August 27, 2022
5

You could use IIF statement like in the next example:

SELECT
   IIF(test_expression, value_if_true, value_if_false) AS FIELD_NAME
FROM
   TABLE_NAME
Wednesday, September 7, 2022
 
4

Even if you set Persist Security Info=true OR Persist Security Info=false it won't show a difference up front. The difference is happening in the background.

When Persist Security Info=False, security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state.

If you set Persist Security Info=True, Windows will remember the password specified in the connection string.

That's the difference.

MSDN Explanation

Setting Persist Security Info true or false will come into effect only if you mention username and password in the connection string. If you mention username and password in the connection string and set Persist Security Info as false then the credentials cannot be extracted, but if you set Persist Security Info as true while giving credentials in the connection string, windows will remember the credentials, and it can be extracted programmatically.

Monday, October 10, 2022
 
pygri
 
1

To load a 32-bit native library you need to have a 32-bit JVM.

You don't need to uninstall Java, you can have as many version installed as you like.

You can use your 64-bit JVM to talk to a 32-bit JVM which loads your driver, but this may be more complicated than you need.

Saturday, December 24, 2022
 
4

Are there any workarounds I can try to get one of these to install?

This is a relatively easy problem to solve.

  1. Uninstall Office using the automated tool
  2. Reinstall Office 2016
  3. Run the following command with an elevated command prompt: AccessDatabaseEngine.exe /quiet

Source: How to install Microsoft.Ace.oledb 32 bit with Office 64-bit?

Saturday, September 10, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :