[英]How to view foxpro registries using php
你能幫幫我嗎? 我需要在php中顯示一個.dbf表的注冊表,並具有以下代碼。
<html>
<form method="get">
<input type="text" name="nrdoc"></input>
<input type="submit"></input>
</form>
<?php
if(isset ($_GET['nrdoc'])){
$thefile = "winges/vcabdoc.DBF";
if($thefile){
include('./dbf_class.php');
$dbf = new dbf_class($thefile);
$num_rec=$dbf->dbf_num_rec;
$field_num=$dbf->dbf_num_field;
$endexct = $timer->end();
echo("<blockquote>File Name : $thefile<br>Number of Records : $num_rec<br>Number of Fields : $field_num</blockquote>");
echo('<table border=1 cellspacing=0>');
echo('<tr>');
echo('<td>No. </td>');
for($j=0; $j<$field_num; $j++){
echo '<td> '.$dbf->dbf_names[$j]['name'];
if ($dbf->dbf_names[$j]['type']!='M') {
echo '<br>Length='.$dbf->dbf_names[$j]['len'];
}
echo '<br>Type='.$dbf->dbf_names[$j]['type'].'</td>';
}
echo '</tr>';
$i=$_GET['nrdoc'];
if ($row === $dbf->getRow("SELECT *, FROM winges/vcabdoc.dbf WHERE 'VCANUM' == $i")) {
echo('<tr>');
echo('<td align="right">'.str_pad($i+1, 3, "0", STR_PAD_LEFT).'</td>');
for($j=0; $j<$field_num; $j++){
if ($dbf->dbf_names[$j]['type']=='N') {
echo '<td align="right">';
}
else {
echo '<td align="left">';
}
echo htmlentities($row[$j]).' </td>';
}
echo '<tr>';
}
}
echo('</table>');
}
?>
</html>
dbf_class.php來自http://www.phpclasses.org
它總是返回數據庫上的第一個數據行,請幫幫我。
提前致謝。
若昂
我找到了一種使用perl庫XBASE從.dbf中提取數據的簡單方法使用這個庫,我編寫了一個小腳本,它讀取給定文件並輸出一個json字符串。
# foxpro2json.pl
use File::Basename;
use XBase;
$filename=$ARGV[0];
my $table = new XBase $filename or die XBase->errstr;
my @fields = $table->field_names;
my $cursor = $table->prepare_select();
my $return = '';
my $i = 0;
while (my @row = $cursor->fetch) {
$json = '{';
$i = 0;
foreach $val (@row) {
$val =~ s/(['"\/\\])/\\$1/g;
$json .= '"'.$fields[$i].'":"'.$val.'",';
$i++;
}
$json = substr($json, 0, -1);
$json .= '},';
$return .= $json;
}
$return = substr($return, 0, -1);
print '['.$return.']';
這就是我在php代碼中調用這個文件的方法:
exec('/usr/bin/perl /var/www/foxpro2json.pl /var/www/myfilename.dbf', $json);
$array = json_decode($json[0], true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.