]> git.defcon.no Git - hermes/blob - api/lib/db_functions.php
6ec0f53766dea32ae5c691619ff6a67088dfa6c4
[hermes] / api / lib / db_functions.php
1 <?php
2 require_once('config.php');
3 require_once('lib/common_functions.php');
4
5 function sql_dbquery( $db, $query )
6 {
7 if ( ! mysql_select_db( $db ) ) return false;
8 $result = mysql_query( $query );
9 if ( !$result ) return false;
10 if (mysql_num_rows($result) == 0) return false;
11 return $result;
12 }
13 function sql_dbexec ( $db, $query )
14 {
15 if ( ! mysql_select_db( $db ) ) return false;
16 $result = mysql_query( $query );
17 if ( !$result ) return false;
18 return $result;
19 }
20 function sql_dbquery_single( $db, $query )
21 {
22 $result = sql_dbquery( $db, $query );
23 if ( ! $result ) return false;
24 if ( mysql_num_rows($result) != 1) return false;
25 $data = mysql_fetch_assoc( $result );
26 return $data;
27 }
28 function sql_dbtest_numrows ( $db, $query, $numrows )
29 {
30 $result = sql_dbquery( $db, $query );
31
32 if ( ! $result ) return false;
33 if ( mysql_num_rows($result) == $numrows ) return true;
34 return false;
35 }
36 function sql_dbexec_rows ( $db, $query )
37 {
38 if ( ! mysql_select_db( $db ) ) return false;
39 $result = mysql_query( $query );
40 if ( !$result ) return -1;
41 return mysql_affected_rows();
42 }
43 function sql_clean( $string )
44 {
45 return addslashes( $string );
46 }
47
48
49 ?>