Heya,

I m having trouble making a query in a .dbf (foxpro) table.
I m using the dbase function to work with my .dbf database.

I m able to retreive all data from the .dbf file using something like this:

$drec = dbase_get_record_with_names($id,$i);
echo $drec['ITM'];

thats for my ITM column, but i was wondering how to make a query like this:

$rowcnt=mysql_query("SELECT ITM FROM dbf_table WHERE id=4");

??

Sorry for my bad english, i hope you understand my question 😕

Cheers
Sharkom

    PHP's dbf functions don't support queries like that. I recommend you transfer your data from dbf files to a MySQL database.

      well, can i convert a mysql file (.sql) to dbf? 🙁

      the dbf files need to be updated each day, so if i can convert the dbf to .sql and then convert it back to .dbf at the end of the day, that would be wonderfull?

      Cheers
      Sharkom

        Am I right in thinking that the dbf files are updated daily by non-web applications and you want to use php and the web to make the contents easily and widely accessible to users?

        If that is the case you only need to convert from dbf to mySql on a daily basis.

          thats right, but i need to be able to update the changes made in mysql into the dbf...

          The dbf contains information on item and product from my inventory. If i sell 1 item, i update my mysql table, but if i cant update the dbf file, the next day my inventory will be the same but i sold 1 item...

          I m using a dbfconverter to put my .dbf into mysql, it works fine, but i need to be able to make my way around and create/update a dbf file from my update mysql file at the end of each days.

          thanks again for your help

            i m wondering 1 thing... the dbase function is useless if we cant make queries in a dbf file. It just put all the data in an array... ? thats weird

              I think you are going to have to 'bite the bullet' and completely transfer away from the dbf files if you also want to update the database via php/web. Otherwise you're going to have two versions of your data and you'll never know which is the correct one.

                wow, thats what i was think, creating a new dbf file at each end of day. Creating a dbf file isnt to hard but i have a load of data in my sql 🙁

                It must be a way to search in a dbf file with making chop in array. That way doesnt seem easy too....

                ... ouch...

                No pain no gain...

                Thx for your help
                Sharkom

                  look at that:

                  $dbname="cat_specs.dbf";
                  $key="108074";
                  if ( !$fp = dbase_open($dbname,0) ) {
                  echo "Cannot open $dbname\n";
                  exit;
                  }
                  $nr = dbase_numrecords($fp); // Number of records.
                  echo "$nr<br>";
                  for ($i=1; $i <= $nr; $i++) { // From 1 to $nr as you know.
                  $temp = dbase_get_record($fp,$i);
                  if ( chop($temp[0]) == $key ) { // $key comes from FORM via WEB
                  echo "$temp[0] : $temp[1] , $temp[2], $temp[3], $temp[4]<Br>";
                  dbase_close($fp);
                  exit;
                  }
                  }
                  it retrun my specific line...

                    There is no support for indexes or memo fields. There is no support for locking, too. Two concurrent webserver processes modifying the same dBase file will very likely ruin your database.

                    dBase files are simple sequential files of fixed length records. Records are appended to the end of the file and delete records are kept until you call dbase_pack().

                    We recommend that you do not use dBase files as your production database. Choose any real SQL server instead; MySQL or Postgres are common choices with PHP. dBase support is here to allow you to import and export data to and from your web database, because the file format is commonly understood by Windows spreadsheets and organizers.

                    The above is an extract from the php manual

                      Write a Reply...