Restored changes from revisions 1.10, 1.11 and 1.12 which I accidently disregarded...
[openemr.git] / library / sql-ledger.inc
blobd30770319b31830bc5dae2db76f33d46aa904e23
1 <?php
2 /* $Id$ */
3 //  ------------------------------------------------------------------------ //
4 //                OpenEMR Electronic Medical Records System                  //
5 //                    Copyright (c) 2005 oemr.org                            //
6 //                       <http://www.oemr.org/>                              //
7 //  ------------------------------------------------------------------------ //
8 //  This program is free software; you can redistribute it and/or modify     //
9 //  it under the terms of the GNU General Public License as published by     //
10 //  the Free Software Foundation; either version 2 of the License, or        //
11 //  (at your option) any later version.                                      //
12 //                                                                           //
13 //  You may not change or alter any portion of this comment or credits       //
14 //  of supporting developers from this source code or any supporting         //
15 //  source code which is considered copyrighted (c) material of the          //
16 //  original comment or credit authors.                                      //
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 Place, Suite 330, Boston, MA  02111-1307 USA //
26 //  ------------------------------------------------------------------------ //
28 $sl_conn = 0; // connection object
29 $sl_err = ""; // global error message
31 function SLConnect() {
32   global $sl_conn, $sl_dbname, $sl_dbuser, $sl_dbpass;
33   $sl_host = $GLOBALS['oer_config']['ws_accounting']['server'];
34   $sl_conn = pg_pconnect("host=$sl_host dbname=$sl_dbname user=$sl_dbuser password=$sl_dbpass");
35   if (!$sl_conn) die("Failed to connect to SQL-Ledger database.");
38 function SLClose() {
39   global $sl_conn;
40   if ($sl_conn) pg_close($sl_conn);
43 function SLQuery($query) {
44   global $sl_conn, $sl_err;
45   $sl_err = "";
46   $res = pg_exec($sl_conn, $query);
47   if (!$res || pg_numrows($res) < 0) {
48     $sl_err = pg_errormessage($sl_conn) . ": $query";
49     if (! $sl_err) $sl_err = "Query failed:" + $query;
50   }
51   return $res;
54 function SLRowCount($res) {
55   return pg_numrows($res);
58 function SLAffectedCount($res) {
59   return pg_affected_rows($res);
62 function SLGetRow($res, $rownum) {
63   return pg_fetch_array($res, $rownum, PGSQL_ASSOC);
66 function SLQueryValue($query) {
67   $res = SLQuery($query);
68   if (! $sl_err && SLRowCount($res) > 0) {
69     $tmp = pg_fetch_array($res, 0);
70     return $tmp[0];
71   }
72   return "";
75 function SLFreeResult($res) {
76   pg_freeresult($res);