答案:
这些说明假定已在主机服务器上设置了 Apache Web 服务器。
操作系统:Windows Server 2003
网络服务器:Apache 2 (WAMP www.wamp.com)
1。
下载并安装适用于 Windows 非 Unicode 驱动程序的 Omnis ODBC 驱动程序 (http://www.tigerlogic.com/tigerlogic/omnis/download/tools.js
2。
为您的数据文件创建一个 SYSTEM 数据源:
-开始菜单 > 管理工具 > 数据源
- 选择“系统 DSN”选项卡
- 点击添加
- 从驱动程序列表中选择“Omnis ODBC 驱动程序”
- 点击完成
- 填写数据源名称、描述和身份验证凭据
重要提示:准确记住数据源名称。这是将用于连接到数据库的数据源的名称。
- 选择数据文件。
-节省
- 数据源现已在操作系统中注册,可以使用了。
3。
在您的 Web 根目录中,创建一个新文件名 odbc_test.php 。
使用以下示例代码测试数据连接。
<?php
/*My data source is named PFDSN, so that is what I will be using in this example
Make sure you use the exact name of the data source created in step 2.
*/
$conn = odbc_connect('PFDSN',' ',' '); //the connection to the data file
$sql = 'select * from INVOICES'; //query string
$result = odbc_exec($conn,$sql); //execute the query
$while($data[] = odbc_fetch_array($result)); //loop through the result set
odbc_free_result($result); //unallocate the result set
odbc_close($conn); //because this is good practice
print_r($data);
?>
保存并关闭文件。
导航到http://localhost/odbc_test.php(或文件所在的任何位置)。
如果连接成功,页面将显示从 invoices 表中提取的所有数据的转储。
如果不起作用,请检查以确保连接字符串中的 DSN 名称正确。
如果连接字符串正确但仍然无法正常工作,则可能是 PHP 没有配置 ODBC 模块。但是,您应该注意,从 PHP 5(在 Windows 中)开始,默认启用 ODBC 模块。
可悲的是,在撰写本文时,Tiger Logic 并未提供 Linux/Unix ODBC 驱动程序。希望他们能清醒过来,意识到 Windows 很糟糕。
结局。