/[projects]/misc/horsensspejder-web/inc/mysql.php
ViewVC logotype

Contents of /misc/horsensspejder-web/inc/mysql.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2125 - (show annotations) (download)
Wed Mar 12 19:30:05 2014 UTC (10 years, 2 months ago) by torben
File size: 1936 byte(s)
initial import
1 <?
2 $DB_HOST="localhost";
3 $DB_USER="root";
4 $DB_PASS="root";
5 $DB_DATABASE="horsensspejder";
6
7
8 function cached_query($string, $timeout = 300) {
9 $memc = new Memcache();
10 $memc->addServer("localhost");
11
12 $key = "sql:" . md5($string);
13 $result = $memc->get($key);
14
15 if ($result == false) {
16 $result = query($string);
17 $memc->set($key,$result, 0, $timeout);
18 }
19
20 return $result;
21 }
22
23 function query($string) {
24 global $DB_CONNECTION;
25 global $DB_DATABASE;
26 global $DB_USER;
27 global $DB_PASS;
28 global $DB_HOST;
29
30 if (!$DB_CONNECTION)
31 $DB_CONNECTION=mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
32
33 mysql_select_db($DB_DATABASE, $DB_CONNECTION);
34 $sqlresult=mysql_query($string,$DB_CONNECTION) or die( mysql_error($DB_CONNECTION) );
35 if (!$sqlresult) {
36 return array();
37 }
38 $result = array();
39 while ($row=mysql_fetch_object($sqlresult)) {
40 $result[]=$row;
41 }
42 return $result;
43
44 }
45
46 function squery($string) {
47 global $DB_CONNECTION;
48 global $DB_DATABASE;
49 global $DB_USER;
50 global $DB_PASS;
51 global $DB_HOST;
52
53 if (!$DB_CONNECTION)
54 $DB_CONNECTION=mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
55
56 mysql_select_db($DB_DATABASE, $DB_CONNECTION);
57 $sqlresult=mysql_query($string,$DB_CONNECTION) or die( mysql_error($DB_CONNECTION) );;
58 return mysql_affected_rows();
59 }
60
61 function insert_id() {
62 global $DB_CONNECTION;
63 global $DB_DATABASE;
64 global $DB_USER;
65 global $DB_PASS;
66 global $DB_HOST;
67
68 if (!$DB_CONNECTION)
69 $DB_CONNECTION=mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
70
71 return mysql_insert_id();
72 }
73
74 function escape_string($string) {
75 global $DB_CONNECTION;
76 global $DB_DATABASE;
77 global $DB_USER;
78 global $DB_PASS;
79 global $DB_HOST;
80
81 if (!$DB_CONNECTION)
82 $DB_CONNECTION=mysql_connect($DB_HOST,$DB_USER,$DB_PASS);
83
84 return mysql_real_escape_string($string);
85 }
86
87 ?>

  ViewVC Help
Powered by ViewVC 1.1.20