DBFETCH.PHP Database Fetch Module for Phorm The purpose of this module is to fetch a record or records from a database, based on form data. INSTALLATION To install this module, place the file dbfetch.php in your plugins directory, and add the following line to the registry file registry.php: > dbopn dbfetch.php USE There are three variables which control the operation of this module. The first is $PHORM_MYTABLE, which is discussed in the Phorm documentation. This tells DBFetch which table to retrieve data from. If $PHORM_MYTABLE is an array, DBFetch uses the *last* element in it. The variable $PHORM_DBFETCH tells DBFetch which field or fields to retrieve. If it is not set, DBFetch will retrieve all the fields. Example: $PHORM_DBFETCH = "Name, Email"; The variable $PHORM_DBFWHICH tells DBFetch which record or records to retrieve. Suppose you have a field in your database called "Username" and you want to retrieve the record where this field contains the value "johndoe". You would put: $PHORM_DBWHICH = "Username='johndoe'"; Note the single quotes around the value. It is more likely, however, that you would want to retrieve records based on the value of some form field. If you had a form field named UName, it would look like this: $PHORM_DBWHICH = "Username='$UName'"; If you know SQL syntax, the value of $PHORM_DBWHICH becomes the WHERE clause of the query, and can contain anything that's valid in an SQL WHERE clause. For that matter it can also contain ORDER and GROUP clauses if you wish. If $PHORM_DBWHICH is not set, then all records are retrieved from the database. The values retrieved are returned in two different ways. First, a variable beginning with $db_ is set for each field in the record. So, for example, if you have a field named "FirstName" then its value will be in the variable $db_FirstName. If there is more than one record returned, these variables will reflect the first record. An array named $PHORM_DBFRSLT will contain one element for each record retrieved. Each element is an associative array, with the field names as indices. So $PHORM_DBFRSLT[0][Name] would contain the "Name" value from the first record; $PHORM_DBFRSLT[1][Name] would contain the "Name" value from the second record, and so on. The variable $PHORM_DBFNREC will have the number of records retrieved. That's all there is to it! =========================== Copyright (c) 2002 Holotech Enterprises (phorm@holotech.net) You may freely distribute this program as-is, without modifications, as part of a valid Phorm distribution. If you are not sure whether you have a valid distribution, you can obtain one from http://www.phorm.com/. You may use this program freely, and modify it for your own purposes.