Php, odbc & vfp

被刻印的时光 ゝ 提交于 2019-11-29 05:19:21

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

select * from YourTable.dbf

EDIT PER FEEDBACK

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;";');

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");

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");

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!