midrange.com code scratchpad
Name:
php record access
Scriptlanguage:
PHP
Tabwidth:
4
Date:
10/21/2008 05:40:26 pm
IP:
Logged
Description:

Simple example of record access in PHP
Code:
  1. <html><form method="post" action=recordaccess.php>    
  2. Library (schema): <input type="text" name="lib"><br>  
  3. File (table): <input type="text" name="tbl"><br>      
  4. <input type="reset"> <input type="submit"             
  5. value="Display records">                              
  6. </form>                                               
  7. </html>                                               
  8.  
  9. ===========================
  10.  
  11. <html>                                                                        
  12. <body>                                                                        
  13. <?php                                                                         
  14. // Get input data                                                             
  15. $i5_server_ip    = "LOCALHOST";  // the hostname of the database server    
  16. $i5_uname        = "PHPUSER";    // The userid                             
  17. $i5_pass         = "password";   // the password                                                                      
  18.                                                                               
  19.                                                                               
  20. $conn = i5_connect($i5_server_ip, $i5_uname, $i5_pass);                       
  21.    if ($conn === false) {                                                     
  22.         print ("<br>FAIL : Failed to connect to server : $i5_server_ip, with  
  23.           user name : $i5_uname and password : $i5_pass");                    
  24.         $errorTab = i5_error();                                               
  25.          var_dump($errorTab);                                                 
  26.         die();                                                                
  27.    }                                                                          
  28. $dbfile = $_POST['tbl'];                                                      
  29. $dblib = $_POST['lib'];                                                       
  30. // Open the file                                               
  31. $file = i5_open("$dblib/$dbfile", $conn);                      
  32. if ($conn === false) {                                         
  33. $errorTab = i5_error();                                        
  34. var_dump($errorTab);                                           
  35. // die("Error while attempting to open file mode=READ");       
  36. die();                                                         
  37. }                                                              
  38. // Print a table row of field names                            
  39. $fields = i5_list_fields($file); // returns an array           
  40. print "<table border=1 cellpadding=3><tr bgcolor=#CCCCCC>";    
  41. // Parse the array                                             
  42. foreach ($fields as $value) {                                  
  43. print "<th>$value</th>";                                       
  44. }                                                              
  45. print "</tr>\n";                                               
  46.                                                                
  47. // Print records                                               
  48. $rec = i5_fetch_row($file, I5_READ_FIRST); // get array     
  49. while ($rec) { // while there is a record...                
  50. // Print each field in the array                            
  51. foreach ($rec as $value) {                                  
  52. print "<td>$value</td>";                                    
  53. }                                                           
  54. print "</tr>\n";                                            
  55. // Get next record                                          
  56. $rec = i5_fetch_row($file, I5_READ_NEXT);                   
  57. // loop                                                   
  58. print "</table>"; // finish off the table                   
  59. ?></body></html>                                            
© 2004-2019 by midrange.com generated in 0.042s valid xhtml & css