forked from SwiftDeal/eCommerce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.database.php
More file actions
83 lines (70 loc) · 2.12 KB
/
Copy pathclass.database.php
File metadata and controls
83 lines (70 loc) · 2.12 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
<?php
require_once($dir_model."config.php");
class MySQLDatabase {
private $connection;
public $last_query;
private $real_escape_string;
private $magic_quotes_active;
function __construct() {
$this->open_connection();
$this->magic_quotes_active = get_magic_quotes_gpc();
$this->real_escape_string = function_exists( "mysql_real_escape_string" );
}
public function open_connection() {
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
if (!$this->connection) {
die("Database connection failed: ".mysql_error());
} else {
$db_select = mysql_select_db(DB_NAME, $this->connection);
if (!$db_select) {
die("Database selection failed: ".mysql_error());
}
}
}
public function close_connection() {
if (isset($this->connection)) {
mysql_close($this->connection);
unset($this->connection);
}
}
public function query($sql) {
$this->last_query = $sql;
$result = mysql_query($sql, $this->connection);
$this->confirm_query($result);
return $result;
}
public function escape_value( $value ) {
if( $this->real_escape_string ) { // PHP v4.3.0 or higher
// undo any magic quote effects so mysql_real_escape_string can do the work
if( $this->magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else { // before PHP v4.3.0
// if magic quotes aren't already on then add slashes manually
if( !$this->magic_quotes_active ) { $value = addslashes( $value ); }
// if magic quotes are active, then the slashes already exist
}
return $value;
}
public function fetch_array($result_set) {
return mysql_fetch_array($result_set);
}
public function num_rows($result_set) {
return mysql_num_rows($result_set);
}
public function insert_id() {
return mysql_insert_id($this->connection);
}
public function affected_rows() {
return mysql_affected_rows($this->connection);
}
private function confirm_query($result) {
if (!$result) {
$output = "Database query failed: ".mysql_error();
$output .= "last sql query ".$this->last_query;
die( $output );
}
}
}
$database = new MySQLDatabase();
$db =& $database;
?>