/[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

Contents of /back/phormation/dbi.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Thu Jul 5 08:11:00 2001 UTC (22 years, 9 months ago) by ravilov
Branch: MAIN
Changes since 1.3: +1 -1 lines
Added a few widgets, cleaned up the code

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

  ViewVC Help
Powered by ViewVC 1.1.26