Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active May 17, 2018 17:11
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dergachev/7372286 to your computer and use it in GitHub Desktop.
Save dergachev/7372286 to your computer and use it in GitHub Desktop.
Figuring out how to talk to MS Access from PHP

Installation

Downloaded Windows XP / IE8 image from http://www.modern.ie/en-us/virtualization-tools

curl -O "https://az412801.vo.msecnd.net/vhd/IEKitV1_Final/VirtualBox/OSX/IE8_XP/IE8.XP.For.MacVirtualBox.ova"

Resources:

Sample access database:

VBScript:

Tips for using Windows:

Running from Linux (alternative to this approach):

<?php
// otherwise PHP gives scary warning messages about default.timezone not being set.
date_default_timezone_set('America/Los_Angeles');
// not sure this got pickd up; I needed to edit C:\Program Files\PHP\php.ini
ini_set('display_errors', 1);
$mdbFilename = $_SERVER['USERPROFILE'] . '\My Documents\test-php\zipcodes.mdb';
echo "File: $mdbFilename\n";
try {
$db = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)}; Dbq=$mdbFilename;Uid=Admin");
echo "PDO connection object created\n";
$sql = "SELECT * From Class";
$stmt = $db->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "$sql\n";
print_r($result);
} catch(PDOException $e) {
echo $e->getMessage();
}
' run me with ...
Wscript.echo "My very first script."
Set conn = CreateObject("ADODB.Connection")
' Connect to the database
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\IEUser\My Documents\Downloads\zipcodes.mdb"
conn.Open strConnect
StrSQL = "Select `Zip Code` from `Zip Codes`"
Set rs = conn.Execute(StrSQL)
Do While not rs.EOF
wscript.echo "The information is " & RS(0)
' intFAQNumber = RS(0)
rs.MoveNext
Loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment