/[corp_html]/back/phormation/dbi.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

Annotation of /back/phormation/dbi.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (hide annotations)
Mon Sep 17 10:35:27 2001 UTC (22 years, 7 months ago) by ravilov
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +1 -1 lines
Fixed/Enhanced the QuickJump feature

1 dpavlin 1.1 <?
2 ravilov 1.10 $debug = false;
3 dpavlin 1.1 /*
4     * Phormation
5     * - A library of PHP code to make development of database-driven
6     * html forms easy and quick
7     *
8     * Copyright (C) 2000 Jason D. Hildebrand
9     * PeaceWorks Computer Consulting
10     *
11     * jason@peaceworks.ca
12     *
13     * This program is free software; you can redistribute it and/or modify
14     * it under the terms of the GNU General Public License as published by
15     * the Free Software Foundation; either version 2 of the License, or
16     * (at your option) any later version.
17     *
18     * This program is distributed in the hope that it will be useful,
19     * but WITHOUT ANY WARRANTY; without even the implied warranty of
20     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21     * GNU General Public License for more details.
22     *
23     * You should have received a copy of the GNU General Public License
24     * along with this program; if not, write to the Free Software
25     * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
26     */
27    
28    
29     function dbi_exec( $conn, $query )
30     {
31 ravilov 1.9 global $DB, $debug;
32     # Convert to ISO-8859-2 (KLUDGY!!!)
33 ravilov 1.7 $query = strtr($query, "ŠÐÈƎšðèæž", "©ÐÈÆ®¹ðèæ¾");
34 ravilov 1.9 if ($debug) echo "<B>[SQL]</B> $query<BR>\n";
35 dpavlin 1.1 if( $DB == "pgsql" ) {
36     $result = pg_exec( $conn, $query );
37     } elseif( $DB == "mysql" ) {
38     $result = mysql_query( $query, $conn );
39     } else {
40     make_error( "DB type is not valid." );
41     }
42     if( ! $result ) {
43     return 0;
44     } else {
45     $array["result"] = $result;
46     $array["row"] = 0;
47     return $array;
48     }
49     }
50    
51     function dbi_fetch_array( $result, $row = "" )
52     {
53     global $DB;
54     $myresult = $result["result"];
55     if( $row == "" ) {
56     // if no row was specified, fetch the next row in the result set
57     if( $DB == "pgsql" ) {
58     $array = pg_fetch_array( $myresult, $result["row"] );
59     $result["row"] += 1;
60     } elseif( $DB == "mysql" ) {
61     $array = mysql_fetch_array( $myresult );
62     } else {
63     make_error( "DB type is not valid." );
64     }
65     return $array;
66     } else {
67     // return the specified row
68     if( $DB == "pgsql" ) {
69     $array = pg_fetch_array( $myresult, $row );
70     $result["row"] = $row + 1;
71     } elseif( $DB == "mysql" ) {
72     $rc = mysql_data_seek( $myresult, $row );
73     if( ! $rc ) {
74     return false;
75     }
76     $array = mysql_fetch_array( $myresult );
77     $result["row"] = $row + 1;
78     } else {
79     make_error( "DB type is not valid." );
80     }
81     return $array;
82     }
83     }
84    
85     function dbi_numrows( $result )
86     {
87     global $DB;
88     $myresult = $result["result"];
89    
90     if( $DB == "pgsql" ) {
91     $n = pg_numrows( $myresult );
92     } elseif( $DB == "mysql" ) {
93     $n = mysql_num_rows( $myresult );
94     } else {
95     make_error( "DB type is not valid." );
96     }
97     return $n;
98     }
99    
100     function dbi_getlastid( $conn, $result, $tablename, $tablekey )
101     {
102     global $DB;
103     if( $DB == "pgsql" ) {
104     $oid = pg_getlastoid( $result["result"] );
105     $result = pg_exec( $conn, "select $tablekey from $tablename where oid = $oid" );
106     $array = pg_fetch_row( $result, 0 );
107     return( $array[0] );
108     } elseif( $DB == "mysql" ) {
109     return( mysql_insert_id( $conn ) );
110     } else {
111     make_error( "DB type is not valid." );
112     }
113     }
114    
115     function dbi_error( $conn )
116     {
117     global $DB;
118     if( $DB == "pgsql" ) {
119     echo "PostgreSQL Error: " . pg_errormessage( $conn ) . "<BR>";
120     } elseif( $DB == "mysql" ) {
121     echo "MySQL Error: " . mysql_errno( $conn ) . " : " . mysql_error( $conn ) . "<BR>";
122     } else {
123     make_error( "DB type is not valid." );
124     }
125     }
126     ?>

  ViewVC Help
Powered by ViewVC 1.1.26