ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
_database Class Reference
+ Collaboration diagram for _database:

Public Member Functions

 __construct ()
 
 connect ()
 
 query ($sql)
 
 nextr ()
 
 get_row ($mode="both")
 
 get_all ($mode="both", $key=false)
 
 f ($index)
 
 go_to ($row)
 
 nf ()
 
 af ()
 
 error ($string="")
 
 insert_id ()
 
 escape ($string)
 
 destroy ()
 
 __construct ()
 
 connect ()
 
 query ($sql)
 
 nextr ()
 
 get_row ($mode="both")
 
 get_all ($mode="both", $key=false)
 
 f ($index)
 
 go_to ($row)
 
 nf ()
 
 af ()
 
 error ($string="")
 
 insert_id ()
 
 escape ($string)
 
 destroy ()
 

Data Fields

 $settings
 

Private Attributes

 $link = false
 
 $result = false
 
 $row = false
 
 $data = false
 

Detailed Description

Definition at line 2 of file class._database.php.

Constructor & Destructor Documentation

◆ __construct() [1/2]

_database::__construct ( )

Definition at line 19 of file class._database.php.

References $db_config, and settings().

19  {
20  global $db_config;
21  $this->settings = array_merge($this->settings, $db_config);
22  if($this->settings["error_file"] === true) $this->settings["error_file"] = dirname(__FILE__)."/__mysql_errors.log";
23  }
$db_config
Definition: config.php:3
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ __construct() [2/2]

_database::__construct ( )

Definition at line 19 of file class._database_i.php.

References $db_config, and settings().

19  {
20  global $db_config;
21  $this->settings = array_merge($this->settings, $db_config);
22  if($this->settings["error_file"] === true) $this->settings["error_file"] = dirname(__FILE__)."/__mysql_errors.log";
23  }
$db_config
Definition: config.php:3
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

Member Function Documentation

◆ af() [1/2]

_database::af ( )

Definition at line 111 of file class._database.php.

111  {
112  return mysql_affected_rows();
113  }

◆ af() [2/2]

_database::af ( )

Definition at line 119 of file class._database_i.php.

References data.

119  {
120  return $this->data->affected_rows;
121  }
Add some data

◆ connect() [1/2]

_database::connect ( )

Definition at line 25 of file class._database.php.

References error(), and settings().

Referenced by query().

25  {
26  if (!$this->link) {
27  $this->link = ($this->settings["persist"]) ?
28  mysql_pconnect(
29  $this->settings["servername"].":".$this->settings["serverport"],
30  $this->settings["username"],
31  $this->settings["password"]
32  ) :
33  mysql_connect(
34  $this->settings["servername"].":".$this->settings["serverport"],
35  $this->settings["username"],
36  $this->settings["password"]
37  ) or $this->error();
38  }
39  if (!mysql_select_db($this->settings["database"], $this->link)) $this->error();
40  if($this->link) mysql_query("SET NAMES 'utf8'");
41  return ($this->link) ? true : false;
42  }
error($string="")
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connect() [2/2]

_database::connect ( )

Definition at line 25 of file class._database_i.php.

References data, error(), and settings().

25  {
26  $this->data = new mysqli(
27  $this->settings["servername"],
28  $this->settings["username"],
29  $this->settings["password"],
30  $this->settings["database"],
31  $this->settings["serverport"]
32  );
33 
34  if(mysqli_connect_errno()) {
35  $this->error("Connection error: ".mysqli_connect_error() );
36  return false;
37  }
38  if(!$this->data->set_charset("utf8")) {
39  $this->error("Error loading character set utf8");
40  return false;
41  }
42  return true;
43  }
Add some data
error($string="")
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ destroy() [1/2]

_database::destroy ( )

Definition at line 139 of file class._database.php.

139  {
140  if (isset($this->result)) mysql_free_result($this->result);
141  if (isset($this->link)) mysql_close($this->link);
142  }

◆ destroy() [2/2]

_database::destroy ( )

Definition at line 146 of file class._database_i.php.

References data.

146  {
147  if(isset($this->result)) $this->result->free();
148  if($this->data) $this->data->close();
149  }
Add some data

◆ error() [1/2]

_database::error (   $string = "")

Definition at line 114 of file class._database.php.

References $error, date, and settings().

Referenced by connect(), get_all(), go_to(), nextr(), nf(), and query().

114  {
115  $error = mysql_error();
116  if($this->settings["show_error"]) echo $error;
117  if($this->settings["error_file"] !== false) {
118  $handle = @fopen($this->settings["error_file"], "a+");
119  if($handle) {
120  @fwrite($handle, "[".date("Y-m-d H:i:s")."] ".$string." <".$error.">\n");
121  @fclose($handle);
122  }
123  }
124  if($this->settings["dieonerror"]) {
125  if(isset($this->result)) mysql_free_result($this->result);
126  mysql_close($this->link);
127  die();
128  }
129  }
$error
Definition: Error.php:17
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
settings()
Definition: settings.php:2
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ error() [2/2]

_database::error (   $string = "")

Definition at line 122 of file class._database_i.php.

References $error, data, date, and settings().

122  {
123  $error = $this->data->error;
124  if($this->settings["show_error"]) echo $error;
125  if($this->settings["error_file"] !== false) {
126  $handle = @fopen($this->settings["error_file"], "a+");
127  if($handle) {
128  @fwrite($handle, "[".date("Y-m-d H:i:s")."] ".$string." <".$error.">\n");
129  @fclose($handle);
130  }
131  }
132  if($this->settings["dieonerror"]) {
133  if(isset($this->result)) $this->result->free();
134  @$this->data->close();
135  die();
136  }
137  }
Add some data
$error
Definition: Error.php:17
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
settings()
Definition: settings.php:2
+ Here is the call graph for this function:

◆ escape() [1/2]

_database::escape (   $string)

Definition at line 134 of file class._database.php.

134  {
135  if(!$this->link) return addslashes($string);
136  return mysql_real_escape_string($string);
137  }

◆ escape() [2/2]

_database::escape (   $string)

Definition at line 141 of file class._database_i.php.

References data.

141  {
142  if(!$this->data) return addslashes($string);
143  return $this->data->escape_string($string);
144  }
Add some data

◆ f() [1/2]

_database::f (   $index)

Definition at line 95 of file class._database.php.

References $index.

Referenced by get_all().

95  {
96  return stripslashes($this->row[$index]);
97  }
$index
Definition: metadata.php:60
+ Here is the caller graph for this function:

◆ f() [2/2]

_database::f (   $index)

Definition at line 100 of file class._database_i.php.

References $index.

100  {
101  return stripslashes($this->row[$index]);
102  }
$index
Definition: metadata.php:60

◆ get_all() [1/2]

_database::get_all (   $mode = "both",
  $key = false 
)

Definition at line 82 of file class._database.php.

References $key, array, error(), f(), get_row(), and nextr().

82  {
83  if(!$this->result) {
84  $this->error("No query pending");
85  return false;
86  }
87  $return = array();
88  while($this->nextr()) {
89  if($key !== false) $return[$this->f($key)] = $this->get_row($mode);
90  else $return[] = $this->get_row($mode);
91  }
92  return $return;
93  }
error($string="")
get_row($mode="both")
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ get_all() [2/2]

_database::get_all (   $mode = "both",
  $key = false 
)

Definition at line 87 of file class._database_i.php.

References $key, array, error(), f(), get_row(), and nextr().

87  {
88  if(!$this->result) {
89  $this->error("No query pending");
90  return false;
91  }
92  $return = array();
93  while($this->nextr()) {
94  if($key !== false) $return[$this->f($key)] = $this->get_row($mode);
95  else $return[] = $this->get_row($mode);
96  }
97  return $return;
98  }
error($string="")
get_row($mode="both")
Create styles array
The data for the language used.
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

◆ get_row() [1/2]

_database::get_row (   $mode = "both")

Definition at line 60 of file class._database.php.

References $row, and array.

Referenced by get_all().

60  {
61  if(!$this->row) return false;
62 
63  $return = array();
64  switch($mode) {
65  case "assoc":
66  foreach($this->row as $k => $v) {
67  if(!is_int($k)) $return[$k] = $v;
68  }
69  break;
70  case "num":
71  foreach($this->row as $k => $v) {
72  if(is_int($k)) $return[$k] = $v;
73  }
74  break;
75  default:
76  $return = $this->row;
77  break;
78  }
79  return array_map("stripslashes",$return);
80  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ get_row() [2/2]

_database::get_row (   $mode = "both")

Definition at line 65 of file class._database_i.php.

References $row, and array.

65  {
66  if(!$this->row) return false;
67 
68  $return = array();
69  switch($mode) {
70  case "assoc":
71  foreach($this->row as $k => $v) {
72  if(!is_int($k)) $return[$k] = $v;
73  }
74  break;
75  case "num":
76  foreach($this->row as $k => $v) {
77  if(is_int($k)) $return[$k] = $v;
78  }
79  break;
80  default:
81  $return = $this->row;
82  break;
83  }
84  return array_map("stripslashes",$return);
85  }
Create styles array
The data for the language used.

◆ go_to() [1/2]

_database::go_to (   $row)

Definition at line 99 of file class._database.php.

References $row, and error().

99  {
100  if(!$this->result) {
101  $this->error("No query pending");
102  return false;
103  }
104  if(!mysql_data_seek($this->result, $row)) $this->error();
105  }
error($string="")
+ Here is the call graph for this function:

◆ go_to() [2/2]

_database::go_to (   $row)

Definition at line 104 of file class._database_i.php.

References $row, data, and error().

104  {
105  if(!$this->result) {
106  $this->error("No query pending");
107  return false;
108  }
109  if(!$this->data->data_seek($row)) $this->error();
110  }
Add some data
error($string="")
+ Here is the call graph for this function:

◆ insert_id() [1/2]

_database::insert_id ( )

Definition at line 130 of file class._database.php.

130  {
131  if(!$this->link) return false;
132  return mysql_insert_id();
133  }

◆ insert_id() [2/2]

_database::insert_id ( )

Definition at line 138 of file class._database_i.php.

References data.

138  {
139  return $this->data->insert_id;
140  }
Add some data

◆ nextr() [1/2]

_database::nextr ( )

Definition at line 50 of file class._database.php.

References error().

Referenced by get_all().

50  {
51  if(!$this->result) {
52  $this->error("No query pending");
53  return false;
54  }
55  unset($this->row);
56  $this->row = mysql_fetch_array($this->result, MYSQL_BOTH);
57  return ($this->row) ? true : false ;
58  }
error($string="")
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nextr() [2/2]

_database::nextr ( )

Definition at line 55 of file class._database_i.php.

References error().

55  {
56  if(!$this->result) {
57  $this->error("No query pending");
58  return false;
59  }
60  unset($this->row);
61  $this->row = $this->result->fetch_array(MYSQL_BOTH);
62  return ($this->row) ? true : false ;
63  }
error($string="")
+ Here is the call graph for this function:

◆ nf() [1/2]

_database::nf ( )

Definition at line 107 of file class._database.php.

References error().

107  {
108  if ($numb = mysql_num_rows($this->result) === false) $this->error();
109  return mysql_num_rows($this->result);
110  }
error($string="")
+ Here is the call graph for this function:

◆ nf() [2/2]

_database::nf ( )

Definition at line 112 of file class._database_i.php.

References error().

112  {
113  if (!$this->result) {
114  $this->error("nf: no result set");
115  return false;
116  }
117  return $this->result->num_rows;
118  }
error($string="")
+ Here is the call graph for this function:

◆ query() [1/2]

_database::query (   $sql)

Definition at line 44 of file class._database.php.

References connect(), and error().

44  {
45  if (!$this->link && !$this->connect()) $this->error();
46  if (!($this->result = mysql_query($sql, $this->link))) $this->error($sql);
47  return ($this->result) ? true : false;
48  }
error($string="")
+ Here is the call graph for this function:

◆ query() [2/2]

_database::query (   $sql)

Definition at line 45 of file class._database_i.php.

References connect(), data, and error().

45  {
46  if(!$this->data && !$this->connect()) {
47  $this->error("Could node connect for query: ".$sql);
48  return false;
49  }
50  //echo $sql."<br />:";
51  if(!($this->result = $this->data->query($sql))) $this->error($sql);
52  return ($this->result) ? true : false;
53  }
Add some data
error($string="")
+ Here is the call graph for this function:

Field Documentation

◆ $data

_database::$data = false
private

Definition at line 3 of file class._database_i.php.

◆ $link

_database::$link = false
private

Definition at line 3 of file class._database.php.

◆ $result

_database::$result = false
private

Definition at line 4 of file class._database.php.

◆ $row

_database::$row = false
private

Definition at line 5 of file class._database.php.

Referenced by get_row(), and go_to().

◆ $settings

_database::$settings
Initial value:
"servername"=> "localhost",
"serverport"=> "3306",
"username" => false,
"password" => false,
"database" => false,
"persist" => false,
"dieonerror"=> false,
"showerror" => false,
"error_file"=> true
)

Definition at line 7 of file class._database.php.


The documentation for this class was generated from the following files: