aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/web/offline_mysql.php
blob: fe0eb3e78563bf261c45324bf60b7381f179184d (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/*
 * Copyright (c) 2007, 2008 Contributors, http://opensimulator.org/
 * See CONTRIBUTORS for a full list of copyright holders.
 *
 * See LICENSE for the full licensing terms of this file.
 *
*/
 
// This looks like its lifted from http://www.weberdev.com/get_example-4372.html
// I'd contact the original developer for licensing info, but his website is broken.
 
class DB
{
    var $Host = C_DB_HOST;				// Hostname of our MySQL server
    var $Database = C_DB_NAME;			// Logical database name on that server
    var $User = C_DB_USER;				// Database user
    var $Password = C_DB_PASS;			// Database user's password
    var $Link_ID = 0;				// Result of mysql_connect()
    var $Query_ID = 0;				// Result of most recent mysql_query()
    var $Record	= array();			// Current mysql_fetch_array()-result
    var $Row;					// Current row number
    var $Errno = 0;					// Error state of query
    var $Error = "";
 
    function halt($msg)
    {
	echo("</TD></TR></TABLE><B>Database error:</B> $msg<BR>\n");
	echo("<B>MySQL error</B>: $this->Errno ($this->Error)<BR>\n");
	die("Session halted.");
    }
 
    function connect()
    {
	if($this->Link_ID == 0)
	{
	    $this->Link_ID = mysql_connect($this->Host, $this->User, $this->Password);
	    if (!$this->Link_ID)
	    {
		$this->halt("Link_ID == false, connect failed");
	    }
	    $SelectResult = mysql_select_db($this->Database, $this->Link_ID);
	    if(!$SelectResult)
	    {
		$this->Errno = mysql_errno($this->Link_ID);
		$this->Error = mysql_error($this->Link_ID);
		$this->halt("cannot select database <I>".$this->Database."</I>");
	    }
	}
    }
 
    function escape($String)
    {
	return mysql_escape_string($String);
    }
 
    function query($Query_String)
    {
	$this->connect();
	$this->Query_ID = mysql_query($Query_String,$this->Link_ID);
	$this->Row = 0;
	$this->Errno = mysql_errno();
	$this->Error = mysql_error();
	if (!$this->Query_ID)
	{
	    $this->halt("Invalid SQL: ".$Query_String);
	}
	return $this->Query_ID;
    }
 
    function next_record()
    {
	$this->Record = @mysql_fetch_array($this->Query_ID);
	$this->Row += 1;
	$this->Errno = mysql_errno();
	$this->Error = mysql_error();
	$stat = is_array($this->Record);
	if (!$stat)
	{
	    @mysql_free_result($this->Query_ID);
	    $this->Query_ID = 0;
	}
	return $this->Record;
    }
 
    function num_rows()
    {
	return mysql_num_rows($this->Query_ID);
    }
 
    function affected_rows()
    {
	return mysql_affected_rows($this->Link_ID);
    }
 
    function optimize($tbl_name)
    {
	$this->connect();
	$this->Query_ID = @mysql_query("OPTIMIZE TABLE $tbl_name",$this->Link_ID);
    }
 
    function clean_results()
    {
	if($this->Query_ID != 0) mysql_freeresult($this->Query_ID);
    }
 
    function close()
    {
	if($this->Link_ID != 0) mysql_close($this->Link_ID);
    }
}
?>