以下摘自PHP手册You already have all the tools you need if you are running entirely under Windows 9x/Me, or NT/2000, where you can use ODBC and Microsoft's ODBC drivers for Microsoft Access databases.<?php // Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008 $connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);// Microsoft Access $connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);// Microsoft Excel $excelFile = realpath('C:/ExcelData.xls'); $excelDir = dirname($excelFile); $connection = odbc_connect("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=$excelFile;DefaultDir=$excelDir" , '', ''); ?>
// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);// Microsoft Access
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);// Microsoft Excel
$excelFile = realpath('C:/ExcelData.xls');
$excelDir = dirname($excelFile);
$connection = odbc_connect("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=$excelFile;DefaultDir=$excelDir" , '', '');
?>
function getInfo($table,$field,$id,$colnum){
$connstr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=db1.mdb";
$connid = @odbc_connect($connstr,"","",SQL_CUR_USE_ODBC) or die ("數據庫錯誤!");
$sql = "select * from ".$table." where ".$field."=".$id;
$query = @odbc_do($connid,$sql);
if(odbc_fetch_row($query)){
for($i=0;$i<$colnum;$i++){
$info[$i] = odbc_result($query,$i+1);
}
}
return $info;
}
getInfo("order","id",1,2);
?>提示“數據庫錯誤” 這是為什麼呀? 期待高人指點