/[libdata]/branches/pear-db/include/db_connect.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /branches/pear-db/include/db_connect.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 75 by dpavlin, Sat Mar 6 19:26:11 2004 UTC revision 76 by dpavlin, Thu Mar 18 21:47:40 2004 UTC
# Line 1  Line 1 
1  <?php  <?php
2    // Database connection parameters
3    $db_server      = "yourlibrary.edu";
4    $db_user        = "libdata";
5    $db_password    = "changEth1s";
6    $db_name        = "libdata";
7    
8    
9    // Establish a connection to the database server or bail out.
10    $db_link = @xx_connect ($db_server, $db_user, $db_password)
11    or die ( "ERROR: Could not connect to the database server." );
12    
13    
14    // Switch to the selected database name or bail out.
15    $db_switch = @xx_select_db ($db_name, $db_link )
16    or die ( "ERROR: Could not connect to the database." );
17    
18    
19    /**********************************************************
20    Function: xx_tryquery($querystring)
21    Author: Paul Bramscher
22    Last Modified: 03.02.2004
23    ***********************************************************
24    Incoming:
25    $querystring            Typically an SQL statement, although
26                            it can also be other mySQL directives
27                            such as UNLOCK TABLES, etc.
28    ***********************************************************
29    Outgoing:
30    $db_resource            mySQL resource identifier for the
31                            (successful) query.
32    ***********************************************************
33    Purpose:
34    This function traps FALSE results for attempted mySQL
35    queries.  If the $db_debug mode below is toggled on (1),
36    then additional error reporting is displayed.
37    **********************************************************/
38    function xx_tryquery($querystring) {
39    
40            // Database debug mode
41            $db_debug = 0;
42    
43            // Determine whether the query was successful
44            $db_resource = @xx_query($querystring);
45    
46            // Success.
47            if ($db_resource) {
48                    return $db_resource;
49            }
50    
51      /****************************************************************/          // Handle errors
52            else {
53      /* constants */          
54      $DEBUG = 0;         // XXX not used at all?                  // Display debugging information if activated.
55                    if ($db_debug == 1) {
56      /****************************************************************/                          printf("<hr><b>DATABASE ERROR DEBUGGING</b><br><br>\n");
57                            printf("<b>mySQL error:</b><br>\n(#%s) %s<br><br>\n",
58          /* database parameters */                                  xx_errno(), xx_error());
59          #$dsn = 'mysql://libdata:libdatapw@localhost/libdata';                          printf("<b>Attempted query:</b><br>\n%s<hr>\n", $querystring);
60          $dsn = 'pgsql://dpavlin@/libdata';                  }
         $dsn_options = array(  
                 'debug'       => 2,  
                 'portability' => DB_PORTABILITY_ALL,  
         );  
   
     /****************************************************************/  
   
         /* establish a connection to the database or bailout */  
         $db =& DB::connect($dsn, $dsn_options);  
         if (DB::isError($db)) {  
                 XXX_debug($db->getMessage() ." / ".  
                         $db->getUserInfo() . " / ".  
                         $db->getDebugInfo());  
                 # XXX remove this!  
                 print $db->getDebugInfo();  
61                                    
62                  die($db->getMessage());                  // Gracefully end the HTML stream
63                    @xx_query ("UNLOCK TABLES");
64                    die ("<br>The database is experiencing problems.</body></html>\n" );
65          }          }
66    
67      /****************************************************************/  }
   
   
     /* some useful functions */  
   
     /* return an error message from a failed sql query */  
     function sql_err ( $p_sql ) {  
         printf ( "ERROR: Query failed.<br>%s<br>%s: %s<br>\n",  
                  $p_sql, xx_errno(), xx_error() );  
         return 1;  
     }  
   
     /* finish off the html stream and die */  
     function bailout() {  
         die ( "Bailing Out!<br>\n</body></html>\n" );  
     }  
   
   
68  ?>  ?>

Legend:
Removed from v.75  
changed lines
  Added in v.76

  ViewVC Help
Powered by ViewVC 1.1.26