我在unixodbc
中安装了libodbc
和ubuntu 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连接
答案 0 :(得分:0)
更改
$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;";
要
$dataSourceName = "odbc:Driver=$driver;DBQ=$mdb_file;Uid='';Pwd='';";