Nothing 2007-7-12 09:43
PHP连接Access数据库代码
[color=#000000][color=#0000cc]<[/color][color=#0000cc]?[/color][color=#0000ff]php[/color]
[color=#0000ff]$[/color][color=#008080]connstr[/color][color=#0000cc]=[/color][color=#ff00ff]"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="[/color] [color=#0000cc].[/color] [color=#ff0000]realpath[/color][color=#0000cc]([/color][color=#ff00ff]"data.mdb"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000ff]$[/color][color=#008080]connid[/color][color=#0000cc]=[/color][color=#ff0000]odbc_connect[/color][color=#0000cc]([/color][color=#0000ff]$[/color][color=#008080]connstr[/color][color=#0000cc],[/color][color=#ff00ff]""[/color][color=#0000cc],[/color][color=#ff00ff]""[/color][color=#0000cc],[/color][color=#0000ff]SQL_CUR_USE_ODBC[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000ff]$[/color][color=#008080]issuetime[/color][color=#0000cc]=[/color][color=#ff0000]date[/color][color=#0000cc]([/color][color=#ff00ff]"Y-m-d H:i:s"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000ff]$[/color][color=#008080]sql[/color][color=#0000cc]=[/color][color=#ff00ff]"insert into test values("[/color][color=#ff00ff]","[/color][color=#ff00ff]",...)"[/color][color=#0000cc];[/color]
[color=#0000ff]$[/color][color=#008080]result[/color][color=#0000cc]=[/color][color=#ff0000]odbc_exec[/color][color=#0000cc]([/color][color=#0000ff]$[/color][color=#008080]connid[/color][color=#0000cc],[/color][color=#0000ff]$[/color][color=#008080]sql[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000ff]if[/color][color=#0000cc]([/color][color=#0000ff]$[/color][color=#008080]result[/color][color=#0000cc])[/color] [color=#ff0000]echo[/color] [color=#ff00ff]"successful"[/color][color=#0000cc];[/color]
[color=#0000ff]else[/color] [color=#ff0000]echo[/color] [color=#ff00ff]"failed"[/color][color=#0000cc];[/color]
[color=#0000cc]?[/color][color=#0000cc]>[/color]
[color=#0000cc]<[/color][color=#0000cc]?[/color][color=#0000ff]php[/color]
[color=#0000ff]if[/color][color=#0000cc]([/color][color=#0000cc]![/color][color=#ff0000]file_exists[/color][color=#0000cc]([/color][color=#0000ff]$[/color][color=#008080]access_mdb[/color][color=#0000cc])[/color][color=#0000cc])[/color] [color=#0000cc]{[/color]
dexit[color=#0000cc]([/color][color=#ff00ff]"找不到 access 数据库文件 '$access_mdb' ,请检查 access 数据库文件路径设置是否正确;<br>当前程序路径:"[/color][color=#0000cc].[/color][color=#ff0000]dirname[/color][color=#0000cc]([/color][color=#0000ff]__FILE__[/color][color=#0000cc])[/color][color=#0000cc].[/color][color=#ff00ff]" 。"[/color][color=#0000cc],[/color] [color=#ff00ff]'access'[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000cc]}[/color]
[color=#ff0000]register_shutdown_function[/color][color=#0000cc]([/color][color=#ff00ff]'adodbClose'[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000ff]$[/color][color=#008080]dbc[/color] [color=#0000cc]=[/color] [color=#0000ff]new[/color] [color=#ff0000]com[/color][color=#0000cc]([/color][color=#ff00ff]"adodb.connection"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000cc]@[/color][color=#0000ff]$[/color][color=#008080]dbc[/color][color=#0000cc]-[/color][color=#0000cc]>[/color]open[color=#0000cc]([/color][color=#ff00ff]"DRIVER={Microsoft Access Driver (*.mdb)};dbq=$access_mdb;uid=$access_uid;pwd=$access_pwd"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000ff]if[/color][color=#0000cc]([/color][color=#0000ff]$[/color][color=#008080]dbc[/color][color=#0000cc]-[/color][color=#0000cc]>[/color]state [color=#0000cc]=[/color][color=#0000cc]=[/color] 0[color=#0000cc])[/color] [color=#0000cc]{[/color]
[color=#0000cc]@[/color][color=#0000ff]$[/color][color=#008080]dbc[/color][color=#0000cc]-[/color][color=#0000cc]>[/color]Open[color=#0000cc]([/color][color=#ff00ff]"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$access_mdb"[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000ff]if[/color][color=#0000cc]([/color][color=#0000ff]$[/color][color=#008080]dbc[/color][color=#0000cc]-[/color][color=#0000cc]>[/color]state [color=#0000cc]=[/color][color=#0000cc]=[/color] 0[color=#0000cc])[/color] [color=#0000cc]{[/color]
dexit[color=#0000cc]([/color][color=#ff00ff]"无法打开 access 数据库文件!可能原因:<br><blockquote>1.不可识别的数据库格式,如果您确认这是一个合法的 $source_ver 数据库文件,请使用 Access 软件打开并修复后再试!<br>2.工作组信息文件丢失,或是已被其它用户以独占方式打开。<br>3.access 数据库文件访问权限不足,请设置 access 数据库文件完全控制权限,access 数据库文件所在目录可写权限,windows 系统 temp 目录可写权限;<br>4.access 数据库文件设置了用户组访问权限,请正确设置数据库用户名密码。</blockquote>"[/color][color=#0000cc],[/color] [color=#ff00ff]'access'[/color][color=#0000cc])[/color][color=#0000cc];[/color]
[color=#0000cc]}[/color]
[color=#0000cc]}[/color]
[color=#0000cc]?[/color][color=#0000cc]>[/color]
[/color]