royopa/ms-access-dbal-driver

用于MS Access的DBAL驱动程序

dev-master 2015-05-27 16:17 UTC

This package is auto-updated.

Last update: 2024-08-29 04:14:28 UTC


README

Build Status

Microsoft Access的DBAL驱动程序。

需求/加载

如果您使用Composer管理依赖项,您可以在composer.json文件中包含以下内容

{
    "require": {
        "royopa/ms-access-dbal-driver": "dev-master"
    }
}

用法

<?php
header('Content-Type: text/html; charset=utf-8');

require 'vendor/autoload.php';

$dsn = 'odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=MyDatabase.mdb;';

try {
    $connPdo = new PDO($dsn);
} catch (PDOException $e) {
    echo $e->getMessage() . '</br>';
}

$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
    'user'     => null,
    'password' => null,
    'pdo'      => $connPdo,
    'driverClass' => 'Royopa\Doctrine\DBAL\Driver\MSAccess\Driver\Driver',
);

$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);

$sql = 'SELECT * FROM myTable';
$stmt = $conn->query($sql);

while ($row = $stmt->fetch()) {
    echo $row['columnName'] . '</br>';
}