home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / foxproodbc.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  2.7 KB  |  97 lines

  1. Foxpro via ODBC 
  2.  
  3. Example script of using ODBC to connect to a Visual Foxpro FREE TABLE directory and execute simple sql query. Please note:- this code is generic ODBC SQL. It should work with any ODBC database. 
  4.  
  5.  
  6. <? 
  7.  
  8. //__________________________________________________________ 
  9. // 
  10. //      foxpro.php 
  11. //      test odbc interface to visual foxpro free tables 
  12. //__________________________________________________________ 
  13. // 
  14.                   
  15.                   
  16. //__________________________________________________________ 
  17. function Error_Handler( $msg, $cnx ) { 
  18. // 
  19.     echo  "$msg \n"; 
  20.     odbc_close( $cnx); 
  21.     exit(); 
  22.  
  23. //__________________________________________________________ 
  24. function format_data( $data ) { 
  25. // 
  26.     $dat = trim($data); 
  27.     if (strlen($dat) == 0 || $dat ==  "1899-12-30" || $dat ==  "0") 
  28.         $dat =  " "; 
  29.     return $dat; 
  30.                   
  31. //---------------------------------------------------------- 
  32. // mainline 
  33. //---------------------------------------------------------- 
  34.  
  35. odbc_close_all(); 
  36. $cnx = odbc_connect(  "beauty",  "",  "" );               
  37. if( ! $cnx ) { 
  38.     Error_handler(  "Error in odbc_connect" , $cnx ); 
  39.                   
  40. echo  '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'; 
  41. echo  "\n<html>\n"; 
  42. echo  "<head> 
  43. <STYLE type='text/css'> 
  44. <!-- 
  45.       th { 
  46.       FONT-FAMILY: 'Tahoma','Arial'; 
  47.       color: red; 
  48.       FONT-SIZE: 10pt; 
  49.       FONT-WEIGHT: bold; 
  50.       Font-style: normal; 
  51.       } 
  52.       td { 
  53.       FONT-FAMILY: 'Tahoma','Arial'; 
  54.       color: black; 
  55.       FONT-SIZE: 10pt; 
  56.       FONT-WEIGHT: bold; 
  57.       Font-style: normal; 
  58.       } 
  59. --> 
  60.  </STYLE>"; 
  61. echo  "</head>\n"; 
  62. echo  "<body>\n"; 
  63. $cur = odbc_exec( $cnx,  "select * from product where lower(desc2) like '%perfume%'" ); 
  64. if( ! $cur ) { 
  65.     Error_handler(  "Error in odbc_exec( no cursor returned ) " , $cnx ); 
  66. }                
  67.                   
  68. echo  "<table border=1 align='center' bgcolor='#ffefef' cellpadding=1 cellspacing=1>\n"; 
  69. $nfields = odbc_num_fields($cur);  
  70. for($i= 1; $i <= $nfields; $i++ ) {  
  71.     if (odbc_field_name($cur, $i) !=  "note") { 
  72.            echo( "<TH>" . odbc_field_name($cur, $i) .  "</TH>");  
  73.     } 
  74. }  
  75. echo( "</TR>\n");  
  76. while(odbc_fetch_row($cur)) {  
  77.        echo( "<TR>"); 
  78.        for($j = 1; $j <= $nfields; $j++) { 
  79.            if (odbc_field_name($cur, $j) !=  "note") { 
  80.                $value = format_data(odbc_result($cur, $j)); 
  81.             echo( "<TD>" . $value .  "</TD>"); 
  82.         } 
  83.     }  
  84.     echo( "</TR>\n");  
  85. echo( "</TABLE>"); 
  86.                  
  87. odbc_close( $cnx); 
  88. echo  "</body>\n"; 
  89. echo  "</html>\n";    
  90.             
  91. ?>
  92.  
  93.