无法连接php与Linux上的ms访问数据库

时间:2017-05-25 12:01:01

标签: php unixodbc

我在unixodbc中安装了libodbcubuntu 14.0,并在此配置了

/etc/odc.ini 
[MyDriver]
Description = MyDriver Driver for MyDBMS
Driver      = /path/to/libmyodbc.so
Setup       = /path/to/libmyodbcs.so
FileUsage   = 1
UsageCount  = 1

和数据源配置

[MyDataSource]
Description = The Source of My Data
Driver      = MyDriver
ServerName  = localhost
Database    = MyDatabase
UserName    = admin
Password    = something

这里是php代码

$query = 'SELECT * FROM MyTable';
$mdb_file = '/path/to/example.mdb';
$uname = explode(" ",php_uname());
$os = $uname[0];
switch ($os){
  case 'Windows':
    $driver = '{Microsoft Access Driver (*.mdb)}';
    break;
  case 'Linux':
    $driver = 'MDBTools';
    break;
  default:
    exit("Don't know about this OS");
}
$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;";
$connection = new \PDO($dataSourceName,'','');
$result = $connection->query($query)->fetchAll(\PDO::FETCH_ASSOC);
print_r($result);

但是如果我输入sql的用户名,那么通过用户root的访问被拒绝    它与sql连接

1 个答案:

答案 0 :(得分:0)

更改

$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;";

$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;Uid='';Pwd='';";