因为想把access的数据导入mysql,但目前只有两种办法,需要使用Access-to-MySQL Pro 这个软件。但由于没有下载到绿色版的,而且我也不需要全部数据,只要个别字段,所以只好选择第二种方法,写一个程序。所以首先要连接到access数据库,在其中试了一些办法,错误不断,感觉是php版本的问题,语法不太一样。
以下错误估计是还需要加入一个连接文件Php-5.1.1-installer.exe ,具体没有找到。
<?
php
$db = " data/ict.mdb " ;
$conn = new com( " ADODB.Connection " ); // 出错,语法错误,不知道的变量
$connstr = " DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " . realpath ( $db );
// $connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".realpath($db);
$conn -> Open( $connstr );
$rs = new com( " ADODB.RecordSet " );
$rs -> Open( " select * from Download " , $conn , 1 , 1 );
while ( ! $rs -> eof) {
$f = $rs -> Fields( 1 );
echo $f -> value;
$rs -> MoveNext();
}
?>
$db = " data/ict.mdb " ;
$conn = new com( " ADODB.Connection " ); // 出错,语法错误,不知道的变量
$connstr = " DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " . realpath ( $db );
// $connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=".realpath($db);
$conn -> Open( $connstr );
$rs = new com( " ADODB.RecordSet " );
$rs -> Open( " select * from Download " , $conn , 1 , 1 );
while ( ! $rs -> eof) {
$f = $rs -> Fields( 1 );
echo $f -> value;
$rs -> MoveNext();
}
?>
以下代码在php5下通过测试
<?
php
$connstr = " DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " . realpath ( " data/ict.mdb " );
$connid = odbc_connect ( $connstr , "" , "" , SQL_CUR_USE_ODBC);
$sql = " select * from Download " ;
$result = odbc_exec ( $connid , $sql );
if ( $result ) echo " successful " ;
else echo " failed " ;
while ( odbc_fetch_row ( $result )) {
for ( $j = 0 ; $j <= 14 ; $j ++ )
{
echo odbc_result ( $result , $j );
echo " <br> " ;
echo " ************************* " ;
echo " <br> " ;
}
}
?>
$connstr = " DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " . realpath ( " data/ict.mdb " );
$connid = odbc_connect ( $connstr , "" , "" , SQL_CUR_USE_ODBC);
$sql = " select * from Download " ;
$result = odbc_exec ( $connid , $sql );
if ( $result ) echo " successful " ;
else echo " failed " ;
while ( odbc_fetch_row ( $result )) {
for ( $j = 0 ; $j <= 14 ; $j ++ )
{
echo odbc_result ( $result , $j );
echo " <br> " ;
echo " ************************* " ;
echo " <br> " ;
}
}
?>