aboutsummaryrefslogtreecommitdiff
path: root/web/db.inc.php
blob: 950c10e06a99cad1c4a0953cd8e994afd49a220b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
include("config.inc.php");

class db
{
  function db()
  {
    global $db_host;
    global $db_user;
    global $db_pass;
    global $db_name;

    if(mysql_connect($db_host,$db_user,$db_pass)==FALSE)
      {
	echo "Issue connecting to DB on host $db_host.\n";
	return 0;
      }

    if(mysql_select_db($db_name) == FALSE)
      {
	echo "Issue connecting to DB $db_name on host $db_host.\n";
	return 0;
      }

    mysql_query("set names 'utf8'");
  }

  function query ($query)
  {
    if( ($result = mysql_query($query)) == FALSE)
      {
	echo "Syntax problem in '$query' : " . mysql_error() . "\n";
	return 0;
      }

    return $result;
  }

  function insertid ()
  {
    return mysql_insert_id ();
  }

  /**
   * Converts the argument of an SQL request in a format accepted by MySQL.
   *
   * @param[in] value String or integer to use as argument
   *
   * @return The string to use in the request
   */
  function quote_smart($value)
  {
    if (get_magic_quotes_gpc())
      $value = stripslashes($value);

    if (!is_numeric($value))
      $value = "'" . mysql_real_escape_string($value) . "'";

    return $value;
  }
}

?>