root/releases/0.1.2a/units/db/library.php

Revision 2, 1.2 kB (checked in by sven, 3 years ago)

importing elgg-0.1.1a

Line 
1 <?php
2
3     // Database library functions
4
5     // Generalised function to query the database
6     // (returns an array of result rows)
7         function db_query($sql_query) {
8             global $querynum;
9             global $querycache;
10             
11             /*if (isset($querycache[$sql_query])) {
12                 return $querycache[$sql_query];
13             }*/
14             
15             if (!isset($querynum)) {
16                 $querynum = 1;
17             } else {
18                 $querynum++;
19             }
20             global $run_context;
21             // echo "<b>" . $run_context . "</b>&nbsp;&nbsp;" . $sql_query . "<br />";
22             if ($sql_query != "") {
23                 // echo "<!-- $sql_query -->\n";
24                 if ($result = @mysql_query($sql_query)) {
25                     $data = array();
26                     if (!is_bool($result)) {
27                         while ($row = @mysql_fetch_object($result)){
28                             $data[] = $row;
29                         }
30                     }
31                     $querycache[$sql_query] = $data;
32                     return $data;
33                 } else {
34                     // echo $sql_query . " :: " . @mysql_error() . "<br />\n";
35                     $querycache[$sql_query] = FALSE;
36                     return FALSE;
37                 }
38             } else {
39                 return FALSE;
40             }
41         }
42     
43     // Rows affected by the last MySQL transaction
44         function db_affected_rows() {
45             return @mysql_affected_rows();
46         }
47         
48     // Returns the ID of the last MySQL transaction
49         function db_id() {
50             return @mysql_insert_id();
51         }
52
53 ?>
Note: See TracBrowser for help on using the browser.