php,odbc& vfp [英] Php, odbc & vfp

查看:93
本文介绍了php,odbc& vfp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将dbf数据库与php连接.我尝试了几种不同的方法,但是没有运气.

I'm trying to connect a dbf database with php. I've tried several different ways, with no luck.

PHP:5.3.8 文件:C:\ xampp \ htdocs \ work \ vcabdoc.dbf

PHP: 5.3.8 File: C:\xampp\htdocs\work\vcabdoc.dbf

创建的数据源dbvfp,驱动程序C:\ Windows \ system32 \ vfpodbc.dll

created data source dbvfp, driver C:\Windows\system32\vfpodbc.dll

已使用$odbc = odbc_connect ('dbvfp', '', '') or die('Could Not Connect to ODBC Database!');

Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Visual FoxPro Driver]File c:\xampp\htdocs\work\vcabdoc.dbf is not a database., SQL state S1000 in SQLConnect in C:\xampp\htdocs\WORK\odbc.php on line 5

第二种方式:

include('\xampp\php\PEAR\adodb\adodb.inc.php');
include_once('\xampp\php\PEAR\adodb\adodb-pager.inc.php');
session_start();
$db = ADONewConnection('vfp');
$dsn="Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=C:\\xampp\\htdocs\\work\\vcabdoc.dbf;Exclusive=No;";
$db->Connect($dsn) or die('nope');
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$query = "Select * from vcabdoc.dbf";
$rs = $db->Execute($query);
echo 'e';
while (!$rs->EOF) {
    print_r($rs->fields);
    $rs->MoveNext();


Notice: Trying to get property of non-object in C:\xampp\htdocs\WORK\testing.php on line 45
Notice: Trying to get property of non-object in C:\xampp\htdocs\WORK\testing.php on line 46
Fatal error: Call to a member function MoveNext() on a non-object in C:\xampp\htdocs\WORK\testing.php on line 47

第三种方式:

$conn = new COM("ADODB.Connection");
$conn->Open('Provider=VFPOLEDB.1;Data Source="C:\\xampp\\htdocs\\work\\vcabdoc.dbf;";');
// SQL statement to build recordset.
$rs = $conn->Execute("SELECT * FROM vcabdoc");

echo "<p>List of couriers:</p><hr>";
// Display all the values in the records set
while (!$rs->EOF) { 
    $fv = $rs->Fields("Name");
    echo $fv->value."<br>\n";
    $rs->MoveNext();
} 
$rs->Close(); 

Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for Visual FoxPro<br/><b>Description:</b> Invalid path or file name.' in C:\xampp\htdocs\WORK\testing.php:54 Stack trace: #0 C:\xampp\htdocs\WORK\testing.php(54): com->Open('Provider=VFPOLE...') #1 {main} thrown in C:\xampp\htdocs\WORK\testing.php on line 54

在这种情况下,尝试使用和不使用双斜杠(\).

I this case, tried with and without double slashes (\).

有帮助吗?预先感谢.

此致

Joao

推荐答案

您正在设置的数据源包含.DBF的全名...请不要这样做.数据源应仅指向表所在的物理目录.然后,当您向表发出查询时,它会根据查询的名称在.dbf的路径中查找,找到并返回该值. ...而且,您不需要显式包含.dbf,例如

The data source you are setting is inclusive of the full name of the .DBF... Don't do that. The data source should just point to the physical directory WHERE the table is .... Then, when you issue a query to a table, it looks in the path for a .dbf by the name you are querying, finds it and returns that... Also, you don't need to explicitly include .dbf, such as

从YourTable.dbf中选择*

select * from YourTable.dbf

修改反馈

您正在打开的连接"具有数据源.那就是说它应该在哪里找到数据.连接到VFP源时,只需将源设置为表的物理路径即可.注意,我只是从字符串参数中删除了"VCABDOC.DBF".

Your "connection" that is being opened has a data source. That is telling where it should find the data. When connecting to a VFP source, all you have to do is set the source to the physical path of the table. Notice I just stripped off the "VCABDOC.DBF" from the string parameter.

$conn->Open('Provider=VFPOLEDB.1;Data Source="C:\\xampp\\htdocs\\work;";');

现在,您应该能够直接从位于"c:\ xampp \ htdocs \ work"文件夹中的表进行查询.

NOW, you should be able to just query directly from the table that is located in the "c:\xampp\htdocs\work" folder.

$rs = $conn->Execute("SELECT * FROM vcabdoc");

最后,假设您在"c:\ xampp \ htdocs \ work"文件夹中有多个.dbf表.说一个简单的客户/订单输入系统,您想获取特定人员的所有订单.只要两个表都在同一个文件夹中(即工作),您就可以执行类似的操作

Finally, lets say you have more than one .dbf table in your "c:\xampp\htdocs\work" folder. Say a simple customer / order entry system and you want to get all orders for a specific person. As long as both tables are in the same folder (ie: work), then you could do something like

    $rs = $conn->Execute(
"SELECT customer.*, orders.* 
   FROM customer 
      join orders on customer.ID = orders.customerID 
      order by orders.date");

注意,我没有在查询中显式地添加完整路径PLUS表名.连接知道它将在何处尝试查找表以完成查询.另外,您的连接不允许您向相对路径后退(更接近C :),但允许您向相对路径前进.因此,假设您有类似的目录结构

Notice I'm not explicitly throwing into the query the full path PLUS table name. The connection knows where it will try to find the tables to complete the query. Also, your connection does NOT allow you to go relative path BACKWARDS (closer to C:), but DOES allow you to go relatively FORWARD. So, say you have a directory structure something like

c:\xampp\htdocs\work\
c:\xampp\htdocs\work\SubFolder1
c:\xampp\htdocs\work\SubFolder2

然后您将连接指向原始示例中的工作"文件夹.您可以查询引用查询中的子文件夹.在此查询中,我在每个表名引用之后使用别名",因此我不必在查询的其余部分中显式键入Long表名.它使可读性更容易.

And you make your connection point to the "work" folder as in the original sample. You COULD query referencing the subfolders in your query. In this query, I'm using an "alias" after each table name reference so I don't have to explicitly type the Long table name where used in the rest of the query. It makes for easier readability.

("c" is alias to customers table)
("sft1" is alias to Sub-folder first table )
("sft2" is alias to Sub-folder second table )

select 
      c.*, 
      sft1.someField, 
      sft2.AnotherField
   from 
      customers c
         join SubFolder1\SomeOtherTable sft1
            on c.SomeCommonColumn = sft1.SameCommonColumn
         join SubFolder2\SecondTable sft2
            on c.ADifferentColumn  =sft2.SimilarPurposeColumn

希望这有助于为您澄清一些事情.

Hope this helps clarify some things for you.

这篇关于php,odbc&amp; vfp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆