forked from wolfsoftwaresystemsltd/landtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.php
More file actions
118 lines (106 loc) · 2.84 KB
/
Copy pathmysql.php
File metadata and controls
118 lines (106 loc) · 2.84 KB
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
113
114
115
116
117
118
<?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.
*
*/
include ("mysql2i.class.php");
//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; // Hostname of our MySQL server
var $Database; // Logical database name on that server
var $User; // Database user
var $Password; // 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 __construct($host,$db,$user,$passwd)
{
$this->Host = $host;
$this->Database = $db;
$this->User = $user;
$this->Password = $passwd;
}
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_real_escape_string($this->Link_ID,$String);
}
function query($Query_String)
{
$this->connect();
$this->Query_ID = mysql_query($this->Link_ID,$Query_String);
$this->Row = 0;
$this->Errno = mysql_errno($this->Link_ID);
$this->Error = mysql_error($this->Link_ID);
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);
}
}